Test name | Executions per second |
---|---|
map | 3519979.5 Ops/sec |
set | 3270291.5 Ops/sec |
arr | 333034.3 Ops/sec |
symbol | 3358327.0 Ops/sec |
uid | 3221204.5 Ops/sec |
control | 4663772.0 Ops/sec |
var
map = new Map(),
set = new Set(),
arr = [],
sym = Symbol(),
uid = "some-uid",
item = {}; // not in any
// Create
for (var i = 0; i < 5000; ++i)
{
var obj = {};
map.set(obj, true);
set.add(obj);
arr.push(obj);
obj[sym] = true;
obj[uid] = true;
}
function mapHas(thing)
{
return map.has(thing);
}
function setHas(thing)
{
return set.has(thing);
}
function arrHas(thing)
{
return arr.indexOf(thing) >= 0;
}
function symHas(thing)
{
return thing[sym];
}
function uidHas(thing)
{
return thing[uid];
}
function conHas(thing)
{
return false;
}
mapHas(item);
setHas(item);
arrHas(item);
symHas(item);
uidHas(item);
conHas(item);