finding numbers - array search vs associative object
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
Array.prototype.shuffle = function () {
var m = this.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = this[m];
this[m] = this[i];
this[i] = t;
}
};
//given a target x and an array, find any pairs of elements whose sum is x
var x = 555;
var arr = [];
for (var i=0; i<1000;i++) { arr.push(i) } ;
arr.shuffle();
var arr2 = arr.slice(0,arr.length);
var arrObj = {};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
array search with indexOf |
|
pending… |
associative object/array |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments