admin管理员组文章数量:1425815
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
1 Answer
Reset to default 8It 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.
本文标签: javascriptIs it bad to have setInterval running all the timeStack Overflow
版权声明:本文标题:javascript - Is it bad to have setInterval running all the time? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745390606a2656580.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论