[英]Repeated timing of a void function in C++
I am trying to time a void function 我想尝试一个无效函数
for (size_t round = 0; round < 5; round++) {
cpu_time_start = get_cpu_time();
wall_time_start = get_wall_time();
scan.assign_clusters(epsilon, mu);
cpu_time_end = get_cpu_time();
wall_time_end = get_wall_time();
...
}
The first timing yields 300 seconds, while the next four timings yields 0.000002 seconds. 第一个时间产生300秒,而接下来的四个时间产生0.000002秒。 This indicates that the void function call to assign_clusters
is optimized out. 这表明对assign_clusters
的void函数调用已经过优化。 How can I force my program to execute this time consuming function call every time, and yet still use optimization for the rest of the code? 如何强制我的程序每次执行这个耗时的函数调用,但仍然使用优化代码的其余部分?
What I usually do is to save the result of the function in question and then print it, but since this is a void
function, do I have the same option? 我通常做的是保存有问题的函数的结果然后打印它,但由于这是一个void
函数,我有相同的选项吗?
I use the following optimization flags: -std=c++0x -march=native -O2
我使用以下优化标志: -std=c++0x -march=native -O2
It depends on what is taking the time, to make the fix. 这取决于花时间做什么来修复。
This could be caused by :- 这可能是由以下原因引起的: -
Service starting can be a number of seconds. 服务启动可以是几秒钟。
Disk cache approx 20x speed up. 磁盘缓存加速约20倍。 Memory cache approx 6x speed up State caching, can be unbounded. 内存缓存约6倍加速状态缓存,可以无限制。
I think your code needs to reset the scan object, to ensure it does the work again 我认为您的代码需要重置扫描对象,以确保它再次完成工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.