Split/Join or Replace JS String

Benchmark created by Eric Pascarello on


Preparation HTML

<script>
  var reComma = /,/g;
  var nums = "1";
  for(var i=2;i<1000;i++){
   nums += "," + i;
  }
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
reg exp
var spaced = nums.replace(reComma, ", ");
ready
split join
var spaced = nums.split(",").join(", ");
ready

Revisions

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

  • Revision 1: published by Eric Pascarello on