is perfect power (v4)

Revision 4 of this benchmark created by computerguy103 on


Setup

function isPP1(n) {
      for (var m = 2; m * m <= n; ++ m)
        for (var k = 2; Math.pow(m, k) <= n; ++ k)
          if (Math.pow(m, k) == n) return [m, k];
      return null;
    }
    
    function isPP2(n){
      var maxB = Math.floor(Math.log2(n)+1);
      var maxA = Math.floor(Math.sqrt(n));
      for(var b = 2; b <= maxB; b++) {
          for(var a = 1; a <= maxA; a++) {
            if (Math.pow(a, b) === n) {
              return [a, b];
            }
          }
      }
      return null;
    }
    
    function isPP3(n){
      for (var m = 1; ++m*m <= n;)
        for (var k = 2;;k++) {
          var pow = Math.pow(m,k)
          if (pow == n) return [m,k]
          else if (pow > n) break
        }
      
      return null
    }
    
    var n = Math.floor(Math.random() * 1e8);

Test runner

Ready to run.

Testing in
TestOps/sec
isPP1
isPP1(n);
ready
isPP2
isPP2(n);
ready
isPP3
isPP3(n);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by computerguy103 on
  • Revision 3: published on
  • Revision 4: published by computerguy103 on