Regex-vs-substring

JavaScript performance comparison

Test case created by Ted Goldman

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var regex = /(GM)(C)(.{8})(.{9})(.{1})(.{3})(.{1})(.{3})(.{18})(.{1})(.{18})(.{18})(.{1})(.{138})(.{18})(.{1})(.{8})(.{1})/;
  var str='GMC1234567812345678911231123123456789012345678112345678901234567812345678901234567811234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456781234567890123456781123456781';
  var splits = [{name:'a',start:0,length:2},{name:'a',start:2,length:1},{name:'a',start:3,length:8},{name:'a',start:11,length:9},{name:'a',start:0,length:2},{name:'a',start:0,length:2},{name:'a',start:0,length:2},{name:'a',start:0,length:2},{name:'a',start:0,length:2},{name:'a',start:0,length:2},{name:'a',start:0,length:2}];
  var parsed={};
  var parts;

};
</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
parts = str.match(regex);
parsed.a=parts[0];
pending…
Substring
for (a in splits){
  parsed[splits.name] = str.substring(splits[a].start, splits[a].length);
};
pending…

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

0 Comments