split/join vs replace (v8)

Revision 8 of this benchmark created on


Preparation HTML

<script>
  var str = "",
      small = " ' ' ' ",
      medium = new Array(100).join(" ' "),
      large = new Array(1000).join(" ' "),
      xtralg = new Array(10000).join(" ' ");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
split/join small
str = small.split(/'/g).join("\\'");
ready
replace small
str = small.replace(/'/g, "\\'");
ready
split/join medium
str = medium.split(/'/g).join("\\'");
ready
replace medium
str = medium.replace(/'/g, "\\'");
ready
split/join large
str = large.split(/'/g).join("\\'");
ready
replace large
str = large.replace(/'/g, "\\'");
ready
split/join xtralg
str = xtralg.split(/'/g).join("\\'");
ready
replace xtralg
str = xtralg.replace(/'/g, "\\'");
ready

Revisions

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