javascript - Is it bad to have setInterval running all the time? - Stack Overflow

Does a function like this slow performance or is it considered bad practice?setInterval(function(){if(s

Does a function like this slow performance or is it considered bad practice?

setInterval(function(){
    if(something){
       do something
    }
}, 100);

Seems to me it would be bad to have something constantly running in the background.

Does a function like this slow performance or is it considered bad practice?

setInterval(function(){
    if(something){
       do something
    }
}, 100);

Seems to me it would be bad to have something constantly running in the background.

Share Improve this question asked Oct 5, 2017 at 22:26 NewCodeManNewCodeMan 2276 silver badges17 bronze badges 2
  • If there has to be sth run regularily, what other way would be there?? – Jonas Wilms Commented Oct 5, 2017 at 22:34
  • I don't know. I'm a beginner :o) but I will learn more – NewCodeMan Commented Oct 5, 2017 at 22:36
Add a ment  | 

1 Answer 1

Reset to default 8

It is running a set of instructions every so many milliseconds, so it can "slow things down," depending on how intensive the instructions are and how many other instructions the user is running from other processes or on your webpage.

It is bad practice if not necessary. If your app is an app that does a thing every so many milliseconds, then that is one way to acplish it. If you are resigning to use it because you just can't figure out the correct way of doing your task, you should spend time to find and implement the correct way of doing your task, instead of harassing the user's CPU cycles.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745390607a4625644.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信