Original link: https://blog.chungzh.cn/articles/int-vs-longlong/
When writing a CF question, the algorithm is obviously correct, but it is always TLE. Finally, an array of
long long type was changed to
int , and it turned out to be AC. .
This can’t help but lead me to think, is the operation speed of
long long different?
Not rigorous testing
Since this chicken does not have any knowledge of the basic principles of computers, I had to do a test. Of course, this test is actually very imprecise and has no great reference value.
I’m going to have fun too, hahahaha
- Computer: Lenovo Yoga 14sACH 2021
- System: Windows 11 25163.1010
- CPU: AMD Ryzen 7 5800H with Radeon Graphics (16) @ 3.200GHz
- RAM: 16.0 GB
- Compiler: GCC 11.2.0
Just for the pleasure of the picture, I used Google Benchmark for the first time. It’s actually pretty good to start with.
After many tests, various operations of type
long long are a little slower than
A more professional answer. See performance – C++ int vs long long in 64 bit machine – Stack Overflow for details.
Here’s a related Q&A:
1) If it is best practice to use long long in x64 for achieving maximum performance even for for 1-4 byte data?
No- and it will probably in fact make your performance worse. For example, if you use 64-bit integers where you could have gotten away with 32-bit integers then you have just doubled the amount of data that must be sent between the processor and memory and the memory is orders of magnitude slower. All of your caches and memory buses will crap out twice as fast.
You can try not to use
long long as much as possible. It’s best not to use the rudeness of
#define int long long .
Sui Sui Nian: I haven’t written a blog for more than half a year, and the last update was during the winter vacation hahaha. The whole semester has been very busy, and the next is the third year of junior high.
This article is reproduced from: https://blog.chungzh.cn/articles/int-vs-longlong/
This site is for inclusion only, and the copyright belongs to the original author.