.replace() vs. .split().join() vs .replaceAll() (v46)

Revision 46 of this benchmark created on


Setup

var mystring = 'okay-this-is-a-string';

Test runner

Ready to run.

Testing in
TestOps/sec
.replace(/\-/g,'_')
result = mystring.replace(/\-/g, '_');
ready
.replace(new RegExp("-","gm"),"_")
result = mystring.replace(new RegExp("-", "gm"), "_");
ready
.split('-').join('_')
result = mystring.split('-').join('_');
ready

Revisions

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