我在这里找到了一些测量执行时间的代码 http://www.dreamincode.net/forums/index.php?showtopic=24685
但是,它似乎不适用于对system()的调用.我想这是因为执行跳出当前进程.
clock_t begin=clock();
system(something);
clock_t end=clock();
cout<<"Execution time: "<<diffclock(end,begin)<<" s."<<endl;
Run Code Online (Sandbox Code Playgroud)
然后
double diffclock(clock_t clock1,clock_t clock2)
{
double diffticks=clock1-clock2;
double diffms=(diffticks)/(CLOCKS_PER_SEC);
return diffms;
}
Run Code Online (Sandbox Code Playgroud)
然而,这总是返回0秒...是否有另一种方法可以工作?
此外,这是在Linux中.
编辑:另外,只需添加,执行时间就是几小时.所以准确性并不是真正的问题.
谢谢!
我目前正在使用python中的sprite sheet工具将组织导出到xml文档中,但是我在尝试为预览设置动画时遇到了一些问题.我不太确定如何用python计算帧速率.例如,假设我拥有所有适当的帧数据和绘图功能,我将如何编写时序以每秒30帧(或任何其他任意速率)显示它.
在我的机器上,执行速度d.clear()和之间的执行速度d={}超过100ns,所以很奇怪为什么会使用一个而不是另一个.
import timeit
def timing():
d = dict()
if __name__=='__main__':
t = timeit.Timer('timing()', 'from __main__ import timing')
print t.repeat()
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在C++/Windows中测量微秒的方法.
我读到了关于"时钟"功能,但它只返回毫秒......
有没有办法做到这一点?
现在,我正在尝试确定一种方法来测量特定函数的时间(类似于pthread_create).当然,现在,这些类型的功能都经过了极大的优化,以尽可能少地占用时间; 事实上,我的计时器在用户空间中使用gettimeofday以微秒为单位的计量器无法充分测量任何东西.
通常,如果我可以搞乱内核,我会使用像get_cycles这样的东西来测量原始周期数作为性能指标.但是,我还没有找到在用户空间中执行此操作的方法.有没有办法使用get_cycles(或等效的)或其他更高精度的计时器,我可以在用户空间中使用它来测量极快的功能?
假设我有"堆排序"方法,其复杂时间为O(nlogn).当我在1000000输入上测量此方法的执行时间时,我得到了0.375770669秒.如何从理论上计算出该方法的执行时间?
我正在使用backbone.js创建我的应用程序
如下所示,我有一个layoutView,我用它来渲染布局,还有布局中的迷你配置文件.
我遇到的问题是时间问题.在触发'renderProfile'方法之前,我需要首先完成'render'方法.我怎样才能做到这一点?
Onethingaday.Views.Home ||= {}
class Onethingaday.Views.Home.LayoutView extends Backbone.View
template: JST["backbone/templates/home/layout"]
initialize: ->
@options.user.bind('change',@render,@renderProfile, @)
renderProfile: ->
view = new Onethingaday.Views.Shared.MiniProfileView
user: @options.user
@$('.profile').html view.render().el
render: ->
$(@el).html(@template())
@
Run Code Online (Sandbox Code Playgroud) 我想clock_gettime使用弃用的gettimeofday参考来检查可靠性,但有时会得到奇怪的结果:
#include <stdio.h>
#include <sys/time.h>
#include <iostream>
void clock_gettime_test()
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
long a = tp.tv_nsec;
usleep(250000);
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
long b = tp.tv_nsec;
printf("clock_gettime (%ld - %ld): %lf msec\n", b, a, (b - a)/1000000.0);
}
void gettimeofday_test()
{
struct timeval tv;
gettimeofday(&tv, NULL);
long a = tv.tv_usec;
usleep(250000);
gettimeofday(&tv, NULL);
long b = tv.tv_usec;
printf("gettimeofday (%ld - %ld): %lf msec\n", b, a, (b - a)/1000.0);
}
int main()
{
clock_gettime_test();
gettimeofday_test();
return 0; …Run Code Online (Sandbox Code Playgroud) 我们有应用程序日志记录各种昂贵操作的性能信息.我们使用两者Stopwatch和DateTime.UtcNow我们的日志记录,我们发现这些值可能比预期的要大很多,即使给定DateTime.UtcNow的精度约为20ms.我的问题是什么可能导致这种情况并且可以修复?
记录的信息是:
DateTime.UtcNow)TimeSpan.FromSeconds((after - before) / (double)Stopwatch.Frequency),其中after和before是Stopwatch.GetTimestamp()操作开始和结束时的值DateTime.UtcNow)你会期望EndTime接近StartTime + Duration,但在某些情况下它会离开.我们对10000个这样的测量进行了采样,寻找EndTime和(StartTime + Duration)相差超过20ms的情况.我们发现了以下内容:
机器信息
我正在运行某人的c ++代码来对数据集进行基准测试.我遇到的问题是,我经常得到第一次运行的时间,如果我再次运行相同的代码,这些数字会大幅改变(即28秒到10秒).我认为这是因为CPU的自动缓存.有没有办法刷新缓存,或以某种方式防止这些波动?