Using long long takes twice more time than using int !!!

Okey, I knew that using long long takes more time than using int. It is kinda logical. But, I just got AC on a problem (MAXPR) that took 6.72 seconds with long long (4138250) and then the same solution with all long long changed to int (4138255) took only 2.89 seconds!!!

That’s almost half the time the solution required!! I found this strange. Is this always suppose to be like this?

If you’re on a 64-bit processor, and you’ve compiled your code for 64-bit, then at least some of the time, long is likely to be more efficient because it matches the register size. But whether that will really impact your program much is debatable. Also, if you’re using long all over the place, you’re generally going to use more memory - both on the stack and on the heap - which could negatively impact performance. There are too many variables to know for sure how well your program will perform using long by default instead of int. There are reasons why it could be faster and reasons why it could be slower. It could be a total wash.

The typical thing to do is to just use int if you don’t care about the size of the integer. If you need a 64-bit integer, then you use long. If you’re trying to use less memory and int is far more than you need, then you use byte or short.

And you know these online judges don’t use 64 bit so its obvious long long is slower than int


I didn’t know that :slight_smile:

Thank You

1 Like