measure time program

#include <time.h>

int delay(int time)
{
    int i,j;
    
    for(i =0;i<time;i++)
        for(j=0;j<10000;j++)
            ;
}

int main()
{
        struct timespec start_1, end_1;
        unsigned  long long diff;

        clock_gettime(CLOCK_REALTIME, &start_1);

        delay(10);    // UUT unit under test

        clock_gettime(CLOCK_REALTIME, &end_1);

        diff = 1000000000 * (end_1.tv_sec - start_1.tv_sec) + (end_1.tv_nsec - start_1.tv_nsec);
        printf("the difference is %lld nano seconds
",diff);
        
        return 0;
}

reference : too much

原文地址:https://www.cnblogs.com/youchihwang/p/10497959.html