C how to measure time correctly?

后端 未结 2 1393
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 18:28

This is the \"algorithm\", but when I want to measure the execution time it gives me zero. Why?

#define ARRAY_SIZE 10000
...

clock_t start, end;

start = cl         


        
2条回答
  •  不要未来只要你来
    2021-01-12 18:57

    This is an unreliable way to actually time number of seconds, since the clock() function is pretty low precision, and your loop isn't doing a lot of work. You can either make your loop do more so that it runs longer, or use a better timing method.

    The higher precision methods are platform specific. For Windows, see How to use QueryPerformanceCounter? and for linux see High resolution timer with C++ and Linux?

提交回复
热议问题