如何获得方法的执行时间?是否有Timer实用程序类用于计算任务需要多长时间等等?
Google上的大多数搜索会返回计划线程和任务的计时器的结果,这不是我想要的.
我想知道,在jquery中我怎么能在几秒钟之后隐藏div?比如Gmail的消息.
我已经尽了最大努力,但无法让它发挥作用.
我想跟踪我的代码的性能,所以我使用了存储开始和结束时间System.DateTime.Now.我将两者之间的差异作为执行代码的时间.
我注意到差异似乎并不准确.所以我尝试使用一个Stopwatch对象.事实证明,这更加准确.
谁能告诉我为什么Stopwatch比计算开始和结束时间之间的差异更准确System.DateTime.Now?
顺便说一句,我不是说百分之十.我得到了大约15-20%的差异.
Python 中MATLAB tic和toc函数(http://www.mathworks.com/help/techdoc/ref/tic.html)的最佳模拟是什么?
以高分辨率和可移植性为代码部分计时的最佳方法是什么?
/* Time from here */
ProcessIntenseFunction();
/* to here. */
printf("Time taken %d seconds %d milliseconds", sec, msec);
Run Code Online (Sandbox Code Playgroud)
是否有一个具有跨平台解决方案的标准库?
我想知道我的项目构建需要多长时间,例如通过在构建窗格中显示它.这个选项在Xcode的某处可用吗?
谢谢.
所以我正在制作一个音乐程序,需要多个javascript元素与另一个同步.我一直在使用setInterval,它最初工作得非常好但是随着时间的推移,元素逐渐变得不同步,而音乐程序则很糟糕.
我在网上看到setTimeout更准确,你可以用某种方式设置setTimeout循环但是我还没有找到一个通用版本来说明这是如何实现的.有人可以向我展示一个使用setTimeout无限循环的基本示例.
谢谢.或者,如果有办法通过setInterval或其他功能实现更多同步结果,请告诉我.
编辑:
基本上我有一些像这样的功能:
//drums
setInterval(function {
//code for the drums playing goes here
},8000);
//chords
setInterval(function {
//code for the chords playing goes here
},1000);
//bass
setInterval(function {
//code for the bass playing goes here
},500);
Run Code Online (Sandbox Code Playgroud)
它最初工作得非常好,但是在大约一分钟的过程中,声音明显不同步,因为我已经阅读了setInterval,我读过setTimeout可以更加一致地准确.
我想知道一个操作在Linux shell脚本中需要多长时间.我怎样才能做到这一点?
对于算法的计时(大约以ms为单位),这两种方法中的哪一种更好:
clock_t start = clock();
algorithm();
clock_t end = clock();
double time = (double) (end-start) / CLOCKS_PER_SEC * 1000.0;
Run Code Online (Sandbox Code Playgroud)
要么,
time_t start = time(0);
algorithm();
time_t end = time(0);
double time = difftime(end, start) * 1000.0;
Run Code Online (Sandbox Code Playgroud)
另外,根据Freenode的C++频道中的一些讨论,我知道时钟的分辨率非常差,因此(相对)快速算法的时序将为零.但是,哪个有更好的分辨率time()或clock()?还是一样吗?
我正在尝试计算一些代码.首先我用了一个时间装饰器:
#!/usr/bin/env python
import time
from itertools import izip
from random import shuffle
def timing_val(func):
def wrapper(*arg, **kw):
'''source: http://www.daniweb.com/code/snippet368.html'''
t1 = time.time()
res = func(*arg, **kw)
t2 = time.time()
return (t2 - t1), res, func.__name__
return wrapper
@timing_val
def time_izip(alist, n):
i = iter(alist)
return [x for x in izip(*[i] * n)]
@timing_val
def time_indexing(alist, n):
return [alist[i:i + n] for i in range(0, len(alist), n)]
func_list = [locals()[key] for key in locals().keys()
if callable(locals()[key]) and key.startswith('time')]
shuffle(func_list) # …Run Code Online (Sandbox Code Playgroud) timing ×10
javascript ×2
performance ×2
python ×2
build ×1
c ×1
c# ×1
c++ ×1
clock ×1
datetime ×1
java ×1
jquery ×1
matlab ×1
setinterval ×1
settimeout ×1
shell ×1
stopwatch ×1
timeit ×1
timer ×1
xcode ×1