How to measure the elapsead time below nanosecond for x86?

后端 未结 3 1221
深忆病人
深忆病人 2020-12-30 18:05

I have searched and used many approaches for measuring the elapsed time. there are many questions for this purpose. For example, this question is very good but when you nee

3条回答
  •  渐次进展
    2020-12-30 19:01

    I have developed my first answer and got this solution. But, I still want a solution. Because it is very important to measure the time accurately and with the least impacts. I put this part in a header file and include it in main program files.

    //Header file header.h
    #define count 1000 // number of repetition 
    long long t1_rdtsc, t2_rdtsc, ttotal_rdtsc[count], ttbest_rdtsc = 99999999999999999, elapsed,  elapsed_rdtsc=count, overal_time = OVERAL_TIME, ttime=0;
    int ii=0;
    #define begin_rdtsc\
                        do{\
                            t1_rdtsc=_rdtsc();
    
    #define end_rdtsc\
                            t2_rdtsc=_rdtsc();\
                            ttotal_rdtsc[ii]=t2_rdtsc-t1_rdtsc;\
                        }while (ii++

提交回复
热议问题