integer exponentiation
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var number = 1;
function pow(n, count, acc) {
return (count < 1 ? acc : (count % 2 === 1 ? pow(n, count - 1, acc * n) : pow(n * n, count / 2, acc)));
}
function pow_squaring(n, x){
var r = 1;
while(x > 1){
if(x % 2 === 0) { n*=n; x/=2; }
else { r*=n; x--; }
}
return n*r;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
multiplication |
|
pending… |
squaring |
|
pending… |
built-in (Math.pow) |
|
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
- Revision 2: published and last updated
- Revision 3: published
- Revision 4: published by 4esn0k
0 comments