Factorial cache
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function factorial(n) {
if (n < 1) return 1
else return n * factorial(n - 1)
}
function factorial2(n) {
factorial2.cache = factorial2.cache || [1]
return factorial2.cache[n] || (factorial2.cache[n] = n * factorial2(n - 1))
}
function factorial3(n) {
var res = 1;
for (var i = 2; i <= n; ++i)
res = res * i;
return res;
}
var n
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Factorial |
|
pending… |
Factorial With Cache |
|
pending… |
Iterative Factorial |
|
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 Yehor Lvivski
- Revision 2: published by zaus
- Revision 3: published
- Revision 4: published by Inskandar Hamadrias
0 comments