substringOrReplace (v3)

Revision 3 of this benchmark created by megion on


Test runner

Ready to run.

Testing in
TestOps/sec
substring
var search = "1X3ta 123 132";
var str = "sigh - look performance is not the same because chaining you create the object but do not assign it. For a chain N long you save N-1 assignments. Putting this in a with block certainly breaks if you have properties declared in scope of with, but I'm assuming as per the OP he's not doing thatasdrf461X3ta 123 132trgsbngt7"
var index = str.indexOf(search);
if (index != -1) {
  var str2 = str.substring(0, index) + str.substring(index + search.length, str.length);
}
ready
replace
var search = "1X3ta 123 132";
var str = "sigh - look performance is not the same because chaining you create the object but do not assign it. For a chain N long you save N-1 assignments. Putting this in a with block certainly breaks if you have properties declared in scope of with, but I'm assuming as per the OP he's not doing thatasdrf461X3ta 123 132trgsbngt7"
var str2 = str.replace(search, "");
ready

Revisions

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

  • Revision 3: published by megion on