Javascript code for making my browser slow down

后端 未结 8 1830
野性不改
野性不改 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:50

    Generate an array of numbers in reverse order and sort it.

    var slowDown = function(n){
      var arr = [];
      for(var i = n; i >= 0; i--){
        arr.push(i);
      }
      arr.sort(function(a,b){
        return a - b;
      });
      return arr;
    }
    

    This can be called like so:

    slowDown(100000);
    

    Or whatever number you want to use.

提交回复
热议问题