Trying to understand something about how g++/cpu processes integers at runtime.
I'm measuring how long the following function takes to run:
template<class T>
void speedTest() {
for(T d=0;d<4294967295u;d++)int number;
}
This simple method will run a dumb loop the max value of uint32_t many times
and when I call:
speedTest<uint32_t>();
the software takes an average of 8.15 seconds but when I call:
speedTest<uint64_t>();
the software takes an average of 10.35 seconds.
Why is this happening?
Some possible reasons:
int number;
(could just be for(T d=0;d<4294967295u;d++);
) You could continue your investigation/exercise by providing some assembly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.