【问题标题】:How to check the working time of application? [duplicate]如何查看申请的工作时间? [复制]
【发布时间】:2013-09-23 10:02:50
【问题描述】:

如何查看我的申请的评估处理时间。 比如A、B、C、A+C、B+C、...需要多少时间

【问题讨论】:

  • 保留一组计数器变量并在您执行要跟踪的操作时递增它们?
  • 您实际上是要测量整个应用程序、应用程序的一部分的时间,还是要测量它执行某件事(功能或指令)的次数?
  • @Mats Petersson 正如您从我的问题中看到的那样,我想为我感兴趣的每个操作组合测量时间。整个工作时间只是所有事情的组合。
  • A、B 和 C 是什么?指令还是功能?
  • 程序的部分——例如让 A 为程序加载文件所花费的时间,B - 程序在加载的文件上应用某种算法所花费的时间,C - 执行时间

标签: c++ performance winapi time


【解决方案1】:
  1. 您可以使用gettimeofday()timersub() 函数来获得差异。

  2. 您可以使用clock() 并减去两次。记得#include。

-引用自:

How to subtract two gettimeofday instances?

http://www.cplusplus.com/forum/unices/50561/

What is the best, most accurate timer in C++?

编辑:另一个选项是chrono i/o。提供非常高的精度。 http://howardhinnant.github.io/duration_io/chrono_io.html

【讨论】:

【解决方案2】:

使用 QueryPerformanceCounter()。

LARGE_INTEGER s, e, f;

QueryPerformanceFrequency( &f );
QueryPerformanceCounter( &s );

// TO DO: add your code here

QueryPerformanceCounter( &e );


const __int64 durationMilliseconds = ( e.QuadPart - s.QuadPart ) * 1000 / f.QuadPart;

【讨论】:

    【解决方案3】:

    如果你使用 Linux。命令“时间”可以帮助您:

    $time ./a.out 
    
    real    0m0.137s
    user    0m0.001s
    sys     0m0.001s
    

    【讨论】:

    猜你喜欢
    • 2019-11-08
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多