indexOf vs hash
JavaScript performance comparison
Preparation code
<script>
var arr = [],
hash = {};
for (var i = 0; arr.length < 1000; i++) {
var t = Math.floor(Math.random() * 5000);
if (!hash[t]) {
hash[t] = 1;
arr.push(1);
}
}
console.log(arr, hash);
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
indexOf |
|
pending… |
hash |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments