IF AND vs Obj Lookup

JavaScript performance comparison

Test case created

Info

Test multiple IF AND conditions against an object lookup

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var account_number = '1110000200';
    var lookup_if = ['1110000136', '1110000138', '1110000127', '1110000139', '1110000140', '1110000167'];
    var lookup_table = {
      '1110000136': 1,
      '1110000138': 1,
      '1110000127': 1,
      '1110000139': 1,
      '1110000140': 1,
      '1110000167': 1
    };
};
</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
IF AND (array)
if (account_number != lookup_if[0] && account_number != lookup_if[1] && account_number != lookup_if[2] && account_number != lookup_if[3] && account_number != lookup_if[4] && account_number != lookup_if[5]) {
  return true;
}
pending…
IF AND (no array)
if (account_number != '1110000136' && account_number != '1110000138' && account_number != '1110000127' && account_number != '1110000139' && account_number != '1110000140' && account_number != '1110000167') {
  return true;
}
pending…
OBJ
if (lookup_table[account_number]) {
  return true;
}
pending…
SWITCH
switch (account_number) {
  case '1110000136':
    return true;
    break;
  case '1110000138':
    return true;
    break;
  case '1110000127':
    return true;
    break;
  case '1110000139':
    return true;
    break;
  case '1110000140':
    return true;
    break;
  case '1110000167':
    return true;
    break;
  default:
    return false;
}
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