regexp vs. string

JavaScript performance comparison

Test case created by Josh D

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var str = 'hello there';
  var matched = 0;
  var regexp = /hello there/;
  var charcodes = "hello there".split("").map(function(x) { return x.charCodeAt(0) });

};
</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
regex
if (regexp.exec(str) != null) {
  matched++;
}
pending…
charcodeat
for (var i = 0, len = str.length; i < len; ++i) {
  if (str.charCodeAt(i) != charcodes[i]) {
    break;
  }
  matched++;
}
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