Sqrt vs Math.sqrt
JavaScript performance comparison
Info
https://gist.github.com/1239433
Preparation code
<script>
var sqrt = (function() {
"use strict";
function sqrt(n, x, p) {
return Math.abs(x * x - n) < p ? x : sqrt(n, (n / x + x) / 2, p);
}
return function(n) {
return sqrt(n, 1, 0.1);
};
})();
</script>
<script>
Benchmark.prototype.setup = function() {
number = 2;
number2 = 3;
function setup() {
number = Math.random() * 10000 | 0;
number2 = Math.random() * 10000 | 0;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Sqrt |
|
pending… |
Math.sqrt |
|
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 sqrt vs Math.sqrt
- Revision 2: published by Daniel Davis
- Revision 3: published
0 comments