In vs test

Benchmark created by Doug Neiner on


Description

If you know only truthy values are going to be stored in an object, using object[ key ] is faster than key in object.

Preparation HTML

<script>
  var tester = {
    key1: true,
    key2: "Positive",
    key3: "Nice"
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
In test
"key1" in tester;
ready
Key test
tester[ "key1" ];
ready
Key undefined test
typeof tester[ "key1" ] !== "undefined";
ready

Revisions

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

  • Revision 1: published by Doug Neiner on