[C++] 代码计时功能库 →→→→→进入此内容的聊天室

来自 , 2020-04-15, 写在 C++, 查看 120 次.
URL http://www.code666.cn/view/f9d11525
  1. /*
  2. **clock.h
  3. **用于代码计时的头文件
  4. **
  5. **clock_begin  :  开始计时.
  6. **clock_end    :   返回从clock_begin开始到此处所用时间并输出.
  7. **clock_num   :  返回从clock_begin开始到此处所用时间但不输出.
  8. **Powered by Viclis
  9. */
  10.  
  11. #include <iostream>
  12. #include <ctime>
  13. using namespace std;
  14.  
  15. #define clock_begin     myclock();
  16. #define clock_end       myclock(true);
  17. #define clock_num       myclock(false)
  18.  
  19. int myclock(bool output=false)
  20. {
  21.         static int a,b;
  22.         static bool k;
  23.         if(k)
  24.         {
  25.                 b=clock();
  26.                 if(output)      printf("This program used %d ms in total.\n",b-a);
  27.                 return b-a;
  28.         }
  29.         else
  30.         {
  31.                 a=clock();
  32.                 k=true;
  33.                 return -1;
  34.         }
  35. }

回复 "代码计时功能库"

这儿你可以回复上面这条便签

captcha