How to measure the time that a piece of code takes to execute?

后端 未结 4 719
说谎
说谎 2020-12-17 01:14

Suppose I want to measure the time that a certain piece of code takes. For that I would normally do something like this

clock_t startTime = clock();
//do stu         


        
4条回答
  •  借酒劲吻你
    2020-12-17 01:21

    This is why code benchmarking basically sucks- because you can't know how long it takes. Things like being pre-empted by the OS are unpredictable at best. Use a professional profiler, as they may have code in them that can deal with these problems, or don't bother. Writing clock() style things is utterly meaningless.

提交回复
热议问题