test key exists in array (v3)

Revision 3 of this benchmark created by Casey on


Preparation HTML

<script>
  var data = {key: 'test 4'};
  data[12] = 'test 1';
  data[13] = 'test 2';
  data[14] = 'test 3';
  
  var array_large = [];
  for (var i = 0; i < 5e5; i++)
     array_large[~~(Math.random() * 1e6)] = i;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
"key" in obj
if("key" in data) {
   return true;
} else {
   return false;
}
ready
obj["key"] != undefined
if(data['key'] !== undefined) {
   return true;
} else {
   return false;
}
ready
array[key]
if (array_large[~~(Math.random() * 1e6)])
    return true;
ready
key in array
if (~~(Math.random() * 1e6) in array_large)
    return true;
ready
array[key] !== undefined
if (array_large[~~(Math.random() * 1e6)] !== undefined)
    return true;
ready

Revisions

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