Key exists check

JavaScript performance comparison

Revision 47 of this test case created

Preparation code

<script>
  var data = Object.create(null);
  var out = {};
  var toCheck;
  var toCheckNotExists;
 
  for (var i = 0; i < 10000; i++) {
   var key = 'user ' + i;
   data[key] =  key + i;

   // toCheck is initialized here to prevent any optimizations for static values
   if ( i == 5000) {
     toCheck = key;
     toCheckNotExists = "not" + key;
   }
  }
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
key in data
out[0] = toCheck in data;
out[1] = toCheckNotExists in data;
pending…
data[key]
out[0] = data[toCheck] !== undefined;
out[1] = data[toCheckNotExists] !== undefined;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment