Easily measure elapsed time

前端 未结 26 2149
栀梦
栀梦 2020-11-22 04:13

I am trying to use time() to measure various points of my program.

What I don\'t understand is why the values in the before and after are the same? I understand thi

26条回答
  •  终归单人心
    2020-11-22 04:53

    They are they same because your doSomething function happens faster than the granularity of the timer. Try:

    printf ("**MyProgram::before time= %ld\n", time(NULL));
    
    for(i = 0; i < 1000; ++i) {
        doSomthing();
        doSomthingLong();
    }
    
    printf ("**MyProgram::after time= %ld\n", time(NULL));
    

提交回复
热议问题