Javascript code for making my browser slow down

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

    Compute lots of square roots manually?

    function sqrt(number, maxDecimal) {
        var cDecimal  = -1;
        var cNumber   = 0;
        var direction = -1;
    
        while(cNumber * cNumber !== number && cDecimal < maxDecimal) {
            direction = -direction;
            cDecimal++;
    
            while((cNumber * cNumber - number) / Math.abs(cNumber * cNumber - number) === direction) cNumber += direction * Math.pow(10, -cDecimal);
        }
    
        return Math.abs(cNumber);
    }
    
    function performTest() {
        for(var i = 0; i < 10000; i++) {
            sqrt(i, 3);
        }
    }
    
    0 讨论(0)
  • 2021-02-19 03:01

    For some reason Bogosort comes to mind. Basically it's a sorting algorithm that consists of:

    while not list.isInOrder():
        list.randomize()
    

    It has an average complexity of O(n * n!) with little memory, so it should slow things down pretty good.

    The main downside is that its running time can be anywhere from O(n) to O(inf) (though really, O(inf) is pretty unlikely).

    0 讨论(0)
提交回复
热议问题