Calculating CPU frequency in C with RDTSC always returns 0

前端 未结 5 1112
情深已故
情深已故 2021-01-13 13:01

The following piece of code was given to us from our instructor so we could measure some algorithms performance:

#include 
#include 

        
5条回答
  •  醉酒成梦
    2021-01-13 13:47

    hmmm I'm not positive but I suspect the problem may be inside this line:

    result = (double) hi * (1 << 30) * 4 + lo;

    I'm suspicious if you can safely carry out such huge multiplications in an "unsigned"... isn't that often a 32-bit number? ...just the fact that you couldn't safely multiply by 2^32 and had to append it as an extra "* 4" added to the 2^30 at the end already hints at this possibility... you might need to convert each sub-component hi and lo to a double (instead of a single one at the very end) and do the multiplication using the two doubles

提交回复
热议问题