Test string compare vs. regex

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var subject = "blah blah blah";
  var visibility = "false";

};
</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
String compare
if ( 
                subject == "Work On Stopped Checked Request"
                || subject == "Work On Checked Request"
                || subject == "Work On Returned Stopped Request"
                || subject == "Work On Returned Request"
                || subject == "Work On Stopped Request"
                || subject == "Work On Updated Request"
                || subject == "Work On Request"
) {
   visibility = "true";
}
pending…
Regex compare
if (/^work on/i.test(subject)) {
   visibility = "true";
}
pending…
Starts with
if (subject.indexOf("Work On") == 0) {
   visibility = "true";
}
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