join/split vs. replace

JavaScript performance comparison

Test case created by Inez

Preparation code

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

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
split and join
var newstr = str.split(' ').join('_');
pending…
replace
var newstr = str.replace(/ /g, '_');
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

2 comments

sdf commented :

adsf

Add a comment