开发者

How much of an effect can CPU have on JavaScript setInterval

开发者 https://www.devze.com 2023-04-11 00:03 出处:网络
I wrote a small jquery plugin that basically converts all words in an html element to spans, makes them invisible and then animates them into view. I made it so that you can define the time开发者_Pyth

I wrote a small jquery plugin that basically converts all words in an html element to spans, makes them invisible and then animates them into view. I made it so that you can define the time开发者_Python百科 that it's supposed to take to load the whole element, and based on tests the math seems to be right, but in practice it takes quite a bit longer.

See jsfiddle: http://jsfiddle.net/A2DNN/

Note the variables "per" and "ms", this basically tells it to process "per" number of words every "ms" milliseconds.

In the log you'll see it'll process 1 word ever 1 ms, which should result in a MUCH faster loading time.

So I'm just wondering, is it possible that the CPU is forming a bottleneck here? In that JS is fading items into view, which is handled by the CPU, which isn't very fast at graphical processing.

It sounds almost silly to ask, I'd expect these days a CPU would laugh at a small bit of work load like this.


It is due to a minimum timeout forced by the browser's JavaScript implementation. You can't have a 1ms timeout, it is slightly more than that. There has already been a discussion about that here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号