Javascript code for making my browser slow down

后端 未结 8 1817
野性不改
野性不改 2021-02-19 02:28

I\'m writing a library for WebWorkers, and I want to test the difference between running a script in the main page thread, versus in one or more workers. The problem is: I can\'

8条回答
  •  礼貌的吻别
    2021-02-19 02:58

    Everyone seems determined to be complicated. Why not this?

    function waste_time(amount) {
        for(var i = 0; i < amount; i++);
    }
    

    If you're concerned the browser will optimize the loop out of existence entirely, you can make it marginally more complicated:

    function waste_time(amount) {
        var tot = 0;
        for(var i = 0; i < amount; i++)
            tot += i;
    }
    

提交回复
热议问题