philly-zipcode2

JavaScript performance comparison

Test case created by Jeffrey Mealo

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var isPhillyZipcode1 = (function () {

      'use strict';
      var re1 = /^191\d{2}/, // Matches: 191##
          re2 = /^191(9[0|5|8|9]|8[0|6|9]|7[4|6]|5[6-9]|6[3-9]|00)/, //matches the holes in sparse 191xx zip code ranges
          re3 = /^192(55|44)/; //Matches the only two 192xx Philadelphia zipcodes
  
      return function(zip) {
          zip = zip + "";
          return (re1.test(zip) && (!re2.test(zip) || re3.test(zip)));
      };
  }());
  
  var isPhillyZipcode2 = (function () {

      'use strict';
      var re1 = /^191\d{2}/, // Matches: 191##
          re2 = /^191(9[0|5|8|9]|8[0|6|9]|7[4|6]|5[6-9]|6[3-9]|00)/, //matches the holes in sparse 191xx zip code ranges
          re3 = /^192(55|44)/; //Matches the only two 192xx Philadelphia zipcodes
  
      return function(zip) {
          zip = String(zip);
          return (re1.test(zip) && (!re2.test(zip) || re3.test(zip)));
      };
  }());

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
isPhillyZipcode1
for (var x = 0, len = 99999; x < len; x++) {
  isPhillyZipcode1(x);
}
pending…
isPhillyZipcode2
for (var x = 0, len = 99999; x < len; x++) {
  isPhillyZipcode2(x);
}
pending…

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

Compare results of other browsers

0 Comments