Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
Chrome 80
Windows
Desktop
5 years ago
Test name Executions per second
Power function (small number) 3276224.2 Ops/sec
Power function (large number) 3251953.2 Ops/sec
Power function (very large number) 3336152.2 Ops/sec
Square root function (small number) 2934460.5 Ops/sec
Square root function (large number) 2964077.2 Ops/sec
Square root function (very large number) 3177536.8 Ops/sec
Script Preparation code:
AخA
 
// Javascript uses floats for numbers. Generaate some numbers in advance.
var smallNumber = Math.pow(2, 7) + Math.floor(Math.random() * Math.pow(2,7));
var largeNumber = Math.pow(2, 30) + Math.floor(Math.random() * Math.pow(2,30));
var veryLargeNumber = Math.pow(2, 60) + Math.floor(Math.random() * Math.pow(2,60));
Tests:
  • Power function (small number)

     
    Math.pow(smallNumber, 2);
  • Power function (large number)

     
    Math.pow(largeNumber, 2);
  • Power function (very large number)

     
    Math.pow(veryLargeNumber, 2);
  • Square root function (small number)

     
    Math.sqrt(smallNumber);
  • Square root function (large number)

     
    Math.sqrt(largeNumber);
  • Square root function (very large number)

     
    Math.sqrt(veryLargeNumber);