Javascript code for making my browser slow down

后端 未结 8 1846
野性不改
野性不改 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);
        }
    }
    

提交回复
热议问题