Replace All vs Split/Join (v44)

Revision 44 of this benchmark created on


Setup

str = "Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test..."
    message = "Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test...Test abc test test abc test..."
    original = "abc"
    replacement = ""
    
    if( typeof ("".replaceAll) == "undefined" )
    Object.defineProperty(String.prototype, "replaceAll", {
        enumerable: false,
        writable: false,
        value: function(find, replace) {
                return this.split('find').join('replace');
        }
    });

Test runner

Ready to run.

Testing in
TestOps/sec
split & join
str.split("abc").join("");
ready
replace
str.replace(/abc/g, '');
ready
lets try that
str.replaceAll('abc', '');
ready

Revisions

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