Caching RegEx Objects

JavaScript performance comparison

Test case created by Chris M. Balz

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  this.sTarget = "Soufflé donut ice cream. Dragée danish jelly beans cotton candy oat cake. Candy canes caramels tiramisu bear claw muffin icing. Marshmallow jujubes faworki dessert. Bear claw chocolate cake chocolate cake brownie sesame snaps brownie faworki. Jelly-o gummi bears fruitcake cotton candy marshmallow jujubes cookie. Pie toffee tart tootsie roll bonbon cake. Halvah sweet pastry cookie croissant chupa chups candy canes. Chocolate jelly chocolate bar caramels applicake cotton candy caramels donut. Toffee jelly-o brownie pie bonbon gummies marshmallow topping. Toffee chupa chups sesame snaps caramels tootsie roll bear claw faworki macaroon chocolate. Jelly beans chupa chups caramels pudding wypas oat cake chocolate cake.";
  
  var rShort = /jelly/ig,
      rLong = /[sy]\s+cookie[^c]+c.{5}/g;
  
    

};

Benchmark.prototype.teardown = function() {
  /*
  console.log( 
    'Results: \n ' + 
        this.sResult1_1 + '\n ' + 
        this.sResult1_2 + '\n ' + 
        this.sResult2_1 + '\n ' + 
        this.sResult2_2
  );
  */

};
</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
Using Cached
this.sResult1_1 = this.sTarget.match(rShort).join();
this.sResult1_2 = this.sTarget.match(rLong).join();
pending…
Using Non-Cached
this.sResult2_1 = this.sTarget.match(/jelly/ig).join();
this.sResult2_2 = this.sTarget.match(/[sy]\s+cookie[^c]+c.{5}/g).join();
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.

0 Comments