Replace : Regexp VS split + join

Benchmark created by jpvincent on


Preparation HTML

<script>
  var sMyString = "the man and the plan";
  
  var oRegexp = /the/g;
  
  var replaceAll = function(sSubject, sFind, sReplaceWith) {
   return sSubject.split(sFind).join(sReplaceWith);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Use regular expression
var sResult = sMyString.replace(oRegexp, 'a');
ready
Use split + join
var sResult = replaceAll(sMyString, 'the', 'a');
ready

Revisions

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

  • Revision 1: published by jpvincent on