Object vs Switch Select (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var obj = {
        a: 1,
        b: 2,
        c: 3,
        d: 4,
        e: 5,
        f: 6,
        g: 7
  },
  val = "a";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object
obj[ val ];
ready
Switch
switch ( val ) {
        case "a": 1; break;
        case "b": 2; break;
        case "c": 3; break;
        case "d": 4; break;
        case "e": 5; break;
        case "f": 6; break;
        case "g": 7; break;
}
ready
Safe Object
obj.hasOwnProperty(val) && obj[ val ];
ready

Revisions

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