IndexOf vs object lookup (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  
  var obj = { a: 1, b: 1, c: 1, d: 1, e: 1, f: 1, g: 1, h: 1, i: 1, j: 1, k: 1, l: 1, m: 1, n: 1, o: 1, p: 1, q: 1, r: 1, s: 1, t: 1, u: 1, v: 1, w: 1, x: 1, y: 1, z: 1 };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
if (arr.indexOf('x') !== -1) {}
ready
Object property access
if (obj.x) {}
ready
Object in
if ('x' in obj) {}
ready
Object.hasOwnProperty
if (obj.hasOwnProperty('x')) {}
ready

Revisions

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