string regexp replace vs loop indexof replaces

Benchmark created on


Preparation HTML

<script>
  var test_str = '1.2.3.4.5.6.7.8.9.0';
  var r = /\./g;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
string replace regexp
test_str.replace(/\./g, ',');
ready
loop indexof
while (test_str.indexOf('.') !== -1) {
   test_str = test_str.replace('.', ',');
}
ready
precompiled regexp
test_str.replace(r, ',');
ready

Revisions

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