How to compare performance of two pieces of codes

前端 未结 7 1432
春和景丽
春和景丽 2020-12-29 11:25

I have a friendly competition with couple of guys in the field of programming and recently we have become so interested in writing efficient code. Our challenge was to try t

7条回答
  •  感动是毒
    2020-12-29 11:58

    There is the std::clock() function from which returns how much CPU time was spent on the current process (that means it doesn't count the time the program was idling because the CPU was executing other tasks). This function can be used to accurately measure execution times of algorithms. Use the constant std::CLOCKS_PER_SEC (also from ) to convert the return value into seconds.

提交回复
热议问题