Calculating time of execution with time() function

前端 未结 5 1432
盖世英雄少女心
盖世英雄少女心 2020-12-07 06:12

I was given the following HomeWork assignment,

Write a program to test on your computer how long it takes to do nlogn, n2, n5, 2n, and n! additions

5条回答
  •  广开言路
    2020-12-07 06:53

    better than time() with second-precision is to use a milliseconds precision. a portable way is e.g.

    int main(){
    clock_t start, end;
    double msecs;
    
    start = clock();
    /* any stuff here ... */
    end = clock();
    msecs = ((double) (end - start)) * 1000 / CLOCKS_PER_SEC;
    return 0;
    }
    

提交回复
热议问题