Reputation: 2065
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?
Upvotes: 2
Views: 2872
Reputation: 7868
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.
Upvotes: 3