« first day (766 days earlier)      last day (2087 days later) » 

3:08 PM
Hello
It is possible to measure code run time correctly with errors < 10 nanoseconds
I try to measure function call (epilogue + prologue) using chrono with a custom QuerryPerformanceCounter implementation
delta between start and end time without any code in between ranges from + 2000 ns to 6000 ns...
HighResClock::time_point startTime1 = HighResClock::now();
HighResClock::time_point endTime1 = HighResClock::now();

HighResClock::duration deltaTime1 = (endTime1 - startTime1);

std::cout << "Size of count: " << sizeof(deltaTime1.count()) << std::endl;
std::cout << "Delta Time 1: " << deltaTime1.count() << std::endl;
 
I don't find it particularly surprising
there's a lot of other stuff running on your machine
better have the code properly repeatable (e.g. do sth 10000 times and take average) instead of measuring it once
 
also measuring itself causes a lot of interference with the timing of what you are measuring
 
@milleniumbug like 1000 and take that median
 
yeah sth like that
 
maybe there exists some better clocks
?
@David
 
3:15 PM
it's not the problem of the clock
it's the problem of that it doesn't measure what you think it measures
e.g. accessing memory for the first time will take longer than accessing it for the second time, because then you have it cached
 
yes you are right, also call for the constructors call to querry performance casting moving data to from registers in start and in end the same
I will make a median with 1 billion calls and I will substract that value
then after inside start and end I will have some with a better error :)
@milleniumbug Thank you!
 
micro benchmarking is very tricky for a variety of reasons, overhead of the timer being one of them
 
@ratchetfreak Accurate profiling for micro code will contain errors. At this level rather than profiling is better to use a table of instructions for each timing (instruction / cycle) specific for the processor you test on (not considering pipeined cpu's).
@milleniumbug great!!
Thanks guys!
 
3:50 PM
@LXSoft That's true/workable for a lot of small embedded systems and such. For a modern desktop/server CPU, you can't look at an instruction in isolation and get a meaningful result. The time to execute an instruction will depend (heavily) on what surrounds it (and yes, since they execute instructions out of order, what follows it can affect how fast it executes).
 

« first day (766 days earlier)      last day (2087 days later) »