split/join vs replace (v5)

Revision 5 of this benchmark created by Ryan 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 + Math.random()).split("'").join("\\'");
ready
replace small
str = (small + Math.random()).replace(/'/g, "\\'");
ready
split/join medium
str = (medium + Math.random()).split("'").join("\\'");
ready
replace medium
str = (medium + Math.random()).replace(/'/g, "\\'");
ready
split/join large
str = (large + Math.random()).split("'").join("\\'");
ready
replace large
str = (large + Math.random()).replace(/'/g, "\\'");
ready
split/join xtralg
str = (xtralg + Math.random()).split("'").join("\\'");
ready
replace xtralg
str = (xtralg + Math.random()).replace(/'/g, "\\'");
ready

Revisions

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