factorial olympics
JavaScript performance comparison
Info
compare imperative vs. recursive factorial
Preparation code
<script>
//assumes n is a non-negative integer
function factorial1(n) {
var r = 1;
while (n>1) {
r = r * n--;
}
return r;
}
//assumes n is a non-negative integer
function factorial2(n) {
return (n<2) ? 1 : factorial2(n-1) * n;
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
imperative 20 |
|
pending… |
imperative 170 |
|
pending… |
recursive 20 |
|
pending… |
recursive 170 |
|
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:
- Revision 1: published by Angus
- Revision 2: published by davsket
- Revision 3: published by Mr. DOS
0 comments