join/split vs. replace

Benchmark created by Inez on


Preparation HTML

<script>
  var str = '';
  for (i = 0; i < 1000; i++) {
    str += "i:" + i + " ";
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
split and join
var newstr = str.split(' ').join('_');
ready
replace
var newstr = str.replace(/ /g, '_');
ready

Revisions

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