MathAndJSFun
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var someData = [0,1,2,3,4,5,6,7,8,9];
function equalsTen (data) {
var dataLen = data.length;
for (var i=0; i<dataLen; i++) {
for (var j=0; j<dataLen; j++) {
if (j != i && (data[i]+data[j]) == 10) {
document.write(data[i]+" and "+data[j]+" are a match <br>");
return true;
}
}
}
document.write("no matches<br>");
return false;
}
function equalsTen2 (data) {
var dataLen = data.length;
for (var i=0; i<dataLen; i++) {
var diff = 10-data[i];
var result = data.indexOf(diff);
if (result > -1 && result != i) {
document.write(data[i]+" and "+data[result]+" are a match <br>");
return true;
}
}
document.write("no matches<br>");
return false;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
2nd Loop |
|
pending… |
Index-Of |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments