I need to emulate set in JavaScript — i.e. variable that is able to answer question "do I contain x?".
Performance of insertion/deletion doesn't matter. Order doesn't matter. And it isn't multiset.
There are two ways to implement it:
Using regular array with value search:
var set = [17, 22, 34]; if (set.indexOf(x)!=-1) ...;
1a. Using TypedArray (e.g. Int32Array), when possible:
var set = Int32Array.of(17, 22, 34); if (set.indexOf(x)!=-1) ...;
Using object with key search:
var set = {17: true, 22: true, 34: true}; if (set[x]) ...;
Theoretically object key search should be much faster (depending on how they implemented it in JS engine, it should be either O(log(n)), or O(1) — vs O(n) on array value search). However, is this a case in JavaScript (where access to object member may require multiple lookups) — especially on small sets with dozens of items? Assuming that values in set are quite simple (either integers, or short strings).
Resume. I want to know: what minimum amount of set items is required to make object key search faster than array value search in case of: (1) values are integers; (2) values are short strings — in modern (2015/2016) web-browsers?
I understand that I can perform measurements myself, but it seems to be irrational to make every developer measure the same things — so I put this question here in case somebody have done it.