Javascript code for making my browser slow down

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

    Try using the obvious (and bad) recursive implementation for the Fibonacci sequence:

    function fib(x) {
      if (x <= 0) return 0;
      if (x == 1) return 1;
      return fib(x-1) + fib(x-2);
    }
    

    Calling it with values of ~30 to ~35 (depending entirely on your system) should produce good "slow down" times in the range you seek. The call stack shouldn't get very deep and the algorithm is something like O(2^n).

提交回复
热议问题