replace-vs-regexp

Benchmark created by kuniwak on


Setup

var BIG_TEXT = '<!--' + Array(10001).join('X') +  '-->';
    var SMALL_TEXT = '<!--XXXXX-->';
    
    var proc1 = function(str) {
      return str.replace(/^<--/, '').replace(/-->$/, '');
    };
    
    var proc2 = function(str) {
      return str.replace(/^<--(.*)-->$/, '$1');
    };

Test runner

Ready to run.

Testing in
TestOps/sec
call replace twice with big text
for(var i = 0; i < 10000; i++){
  proc1(BIG_TEXT);
}
ready
call replace twice with small text
for(var i = 0; i < 10000; i++){
  proc1(SMALL_TEXT);
}
ready
call replace once with big text
for(var i = 0; i < 10000; i++){
  proc2(BIG_TEXT);
}
ready
call replace once with small text
for(var i = 0; i < 10000; i++){
  proc2(SMALL_TEXT);
}
ready

Revisions

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

  • Revision 1: published by kuniwak on