Factorial test my

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script type="text/javascript">
function fac1(x)
{
  var r = 1;
  for(var i=2;i<=x;i++)
  {
    r *= i;
  }
  return r;
}

function fac2(x)
{
  if(x==1)return x;
  return fac2(x-1)*x;
}

function fac3(n) {
return (n!=1) ? n*fac3(n-1) : 1;
}

function fac4(n) {
return n ? n*fac4(n-1) : 1;
}
function fact5(x){
   var res=x;
   while(--x){
      res *= x;
   }
   return res;
}
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Fac1
fac1(1);
fac1(5);
fac1(10);
pending…
Fac2
fac2(1);
fac2(5);
fac2(10);
pending…
Fac3
fac3(1);
fac3(5);
fac3(10);
pending…
Fac4
fac4(1);
fac4(5);
fac4(10);
pending…
fact5
fact5(1);
fact5(5);
fact5(10);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment