简体   繁体   English

计算C ++中多个函数的执行时间

[英]Calculate execution time for multiple functions in C++

I have a function which in turn calls many functions. 我有一个函数,依次调用许多函数。 eg 例如

void fun()
{
f1();
f2();
f3();
....
....
f50();
}

I want to calculate execution time of f1, f2....f50. 我想计算f1,f2 ...... f50的执行时间。 Now if I calculate the time before and after execution of each function and then find the difference, I have to write it for all of these 50 functions which I want to avoid as it looks bad. 现在,如果我计算每个函数执行之前和之后的时间,然后发现差值,那么我必须为这50个函数编写所有代码,由于看起来很糟糕,我想避免使用这些函数。 Is there any simpler way to do this ? 有没有更简单的方法可以做到这一点?

使用一个包装函数,该包装函数将实际函数作为参数调用,并且仅在该包装函数中具有时序代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM