Fork me on GitHub

8/04/2010

[C] 測量程式執行時間

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{ 
    int count,a;
    clock_t c0, c1;
    double cputime;
    c0 = clock();

    /* foo()  */
    for (count = 1l; count < 12345678; count  ) {
        a = 64*64;
    }
    /* end foo( 0 */

    c1= clock();
    cputime = (c1 - c0)/(CLOCKS_PER_SEC );

    printf ("\tElapsed CPU time test:   %f  sec\n",cputime);

    return 0;
}


No comments:

Post a Comment