integer exponentiation
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
number = 1;
function pow(n, x){
var res=1, i;
for(i = 0; i < x; i++){
res *= n;
}
return res;
}
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;
}
};
Benchmark.prototype.teardown = function() {
number = 1;
};
</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