Check string vs regexp

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var tokens = 'jdhf83djsf94h/sdfuhuh/*huh2sdf2uvj333hxcvjkh'.split(/([^a-z]+)/);
  var counter = 0;
  var SLASH = 47;  // /
  var STAR = 32;   // *
  var startsWithComment = /^\/\*/;
  

};
</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
compare
for (var i = 0; i < tokens.length; i++) {
  var token = tokens[i];
  if (token.length >= 2 && token[0] === '/' && token[1] === '*') counter++;
}
pending…
RegExp#test
for (var i = 0; i < tokens.length; i++) {
  var token = tokens[i];
  if(startsWithComment.test(token)) counter++;
}
pending…
compare charCodeAt
for (var i = 0; i < tokens.length; i++) {
  var token = tokens[i];
  if (token.length >= 2 && token.charCodeAt(0) === SLASH && token.charCodeAt(1) === STAR) counter++;
}
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