hash-vs-indexof-2

Benchmark created by hash-vs-indexof on


Setup

var list = ["/62","/15","/65","/62","/15","/08","/01","/65","/62","/65","/62","/15","/01"];

Test runner

Ready to run.

Testing in
TestOps/sec
indexof
var result = [],
    len = list.length;
for (var i = 0; i < len; ++i) {
    if (result.indexOf(list[i]) == -1) {
        result.push(list[i]);
    }
}
ready
hash
var hash = {},
    len = list.length;

for (var i = 0; i < len; ++i) {
    if (!(list[i] in hash)) {
        hash[list[i]] = true;
    }
}

var result = Object.keys(hash);
ready
hash-one-loop
var result = [],
    hash = {},
    len = list.length;

for (var i = 0; i < len; ++i) {
    if (!(list[i] in hash)) {
        hash[list[i]] = true;
        result.push(list[i])
    }
}

 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by hash-vs-indexof on