join/split vs. replace (v3)

Revision 3 of this benchmark created 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(/\s+/).join('_');
ready
replace
var newstr = str.replace(/\s+/g, '_');
ready

Revisions

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