我想看一个函数运行多长时间.在PLT-Scheme中最简单的方法是什么?理想情况下,我希望能够做到这样的事情:
> (define (loopy times)
(if (zero? times)
0
(loopy (sub1 times))))
> (loopy 5000000)
0 ;(after about a second)
> (timed (loopy 5000000))
Took: 0.93 seconds
0
>
Run Code Online (Sandbox Code Playgroud)
这不要紧,如果我不得不使用一些其他类似语法(timed loopy 5000000)或者(timed '(loopy 5000000)),或者如果它返回一个缺点或东西所花费的时间.
我希望按照代码顺序淡化具有某个类的div,每个淡入淡出可能在最后一个之后250毫秒,给人一种逐渐加载页面的印象.
我立刻就褪色了......
$(window).load(function(){
$('div.fade_this_please').fadeIn(4000);
});
Run Code Online (Sandbox Code Playgroud)
但是我不知道我在哪里循环通过每个DIV并在另一个完成时淡入它.
有人能指出我正确的方向!?
任何建议赞赏!
当我调用set timeout时,它返回一个数字,例如
> setTimeout(function(){ console.log('done'); },1000);
4431
"done"
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用这个号码来呼叫,clearTimeout()但这个号码在内部代表什么?
我想备份,删除列表中的每个项目,并在1秒后附加每个项目.
我这样想:
var backup = $('#rGallery').html();
$('#rGallery li').remove();
console.log($(backup).filter('li').length); /* it logs like 135 */
$(backup).filter('li').each(function(){
var the = $(this);
var timeout = setTimeout(function(){
console.log(the.html()); /* it logs the html, but all at the same time*/
$('#rGallery').append('<li>'+the.html()+'</li>');
/*return*/
},1000);
});
Run Code Online (Sandbox Code Playgroud)
它的作品,物品被移除然后再追加,问题是它们都在1秒后被追加.而不是每一个从前一个等待1秒.
我在这里错过了什么?
如何设置2秒超时以等待填充页面控件?我想使用javascript我尝试了以下但无济于事:
setTimeout(function(){},2000);
setTimeout(2000);
Run Code Online (Sandbox Code Playgroud)
有人能提供指针吗?
我正试图通过命令将SKNode移动到屏幕上.我已经设置了以下SKAction链,以便1)节点向上和向外移动,然后2)节点向下移动到起始位置,然后3)开始移动.我已经使用以下代码来尝试实现这个:
SKAction *moveUp = [SKAction moveTo: shipIntroSpot1 duration:3.0];
SKAction *moveDown = [SKAction moveTo:shipSpot1 duration:ship1MovementSpeed];
[self enumerateChildNodesWithName:@"ship1" usingBlock:^(SKNode *node, BOOL *stop) {
NSLog(@"RUNNING MOVE UP");
[node runAction: moveUp];
[node runAction:moveUp completion:^{
NSLog(@"RUNNING MOVE DOWN");
[node setHidden: NO];
[node runAction: moveDown];
}];
[node runAction:moveDown completion:^{
NSLog(@"STARTING MOVEMENT");
}];
Run Code Online (Sandbox Code Playgroud)
但是,SKActions似乎没有以正确的顺序触发.我使用了代码,这样一旦完成一步,下一步就会开始.但是,在下一次SKAction开始工作之前,SKAction似乎没有足够快地移动节点.我的印象是,使用完成调用意味着下一个操作在上一个操作完成之前不会启动?这似乎不是这种情况.另外,如果我为步骤1(向上移动)留下足够长的持续时间,它将跳过步骤2(向下移动)并开始执行步骤3(开始移动).我完全不知道这是怎么回事.如果有人能够指出我在理解如何正确地将不同的行为联系在一起的错误,我将不胜感激.
(我没有做SKAction序列,因为我必须在中途"取消隐藏"节点.我不认为我可以把它放在一个序列中,除非我也错了.)
我有这个代码片段,我在我的程序(C++和OpenCV)中到处使用.它用于计时某些操作:
double t;
// Some code...
t = (double)getTickCount();
Object1.LotOfComputing();
t = 1000*((double)getTickCount() - t)/getTickFrequency();
cout << "Time for LotOfComputing =" << t << " milliseconds."<< endl;
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << endl;
Run Code Online (Sandbox Code Playgroud)
这就是OpenCV doc建议对代码的功能/部分进行计时的方式,它在使用几周后似乎对我有用.我测量的时间从大约1毫秒到700毫秒,我将它们舍入到毫秒.
问题是我在程序中计算了很多不同的操作,代码被这些片段弄得乱七八糟.
我想知道将这些代码行放入函数是否明智,例如:
double timing(double time){
timing = 1000*((double)getTickCount() - time)/getTickFrequency();
cout << "Time for LotOfComputing =" << timing << " milliseconds."<< endl;
cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" << endl;
return timing;
}
Run Code Online (Sandbox Code Playgroud)
所以我可以使用这个:
double t;
// Some code...
t = (double)getTickCount();
Object1.LotOfComputing();
timing(t);
Run Code Online (Sandbox Code Playgroud)
我只关心通过函数调用的执行时间......也许我只是在担心什么都没有!
我试图在水龙头之间保持节奏.但是,我随机获得巨大的价值,我不知道为什么.
@implementation GameScene
{
CFTimeInterval previousFrameTime;
SKLabelNode* myLabel;
}
-(void)didMoveToView:(SKView *)view {
previousTimeFrame = 0.0f;
myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
myLabel.text = @" ";
myLabel.fontSize = 12;
myLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild:myLabel];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
myLabel.text = [NSSTring stringWithFormat: @"%f", previousFrameTime];
}
//Called every frame
-(void)update:(CFTimeInterval)currentTime {
//get the time between frames
previousFrameTime = CACurrentMediaTime() - previousFrameTime;
}
Run Code Online (Sandbox Code Playgroud)
产量:0.65323 0.93527 1.65326 5866.42930 < - ???? 2.52442 5.23156 5888.21345 < - ?????
什么会导致这些随机跳跃?
该%time魔术命令可以让你方便的时间Python的一行代码。
我是否还可以对代码块进行计时而不先将其包装在函数中?是否存在对整个单元进行计时的等效函数?
所以这是我的时间:
>>> import timeit
>>> timeit.timeit(lambda: set(l))
0.7210583936611334
>>> timeit.timeit(lambda: {*l})
0.5386332845236943
Run Code Online (Sandbox Code Playgroud)
为什么这样,我的意见是平等的,但事实并非如此.
因此,从这个例子中拆包很快,对吧?