How can I benchmark C code easily?

前端 未结 4 1017
春和景丽
春和景丽 2020-11-27 11:58

Is there a simple library to benchmark the time it takes to execute a portion of C code? What I want is something like:

int main(){
    benchmarkBegin(0);
           


        
4条回答
  •  萌比男神i
    2020-11-27 12:05

    In POSIX, try getrusage. The relevant argument is RUSAGE_SELF and the relevant fields are ru_utime.tv_sec and ru_utime.tv_usec.

提交回复
热议问题