const input = '<frozen-vendor.68b56447ccf2f3416e7d.js>; rel="script"';
input.replace('<', '')
.replace('>', '')
.replace(' ', '')
const input = '<frozen-vendor.68b56447ccf2f3416e7d.js>; rel="script"';
input.replace(/[<> ]/g, '')
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
With triple replace | |
With regex |
Test name | Executions per second |
---|---|
With triple replace | 2150549.0 Ops/sec |
With regex | 4500848.5 Ops/sec |
Let's dive into the explanation of what is being tested on MeasureThat.net.
Benchmark Purpose: The benchmark measures the performance difference between two approaches for removing unwanted characters from a URL string:
replace()
method with triple quotes (<
and >
)./regex/
) with the /g
flag.Options Compared:
replace()
method to remove <
, >
, and spaces from the URL string.replace()
method./<> /g
) to match and remove <
, >
, and spaces from the URL string.Library Used:
In both test cases, no external library is used. The replace()
method and regular expression engine are built-in JavaScript features.
Special JS Features/Syntax:
None mentioned in this benchmark. However, it's worth noting that some browsers might have specific syntax or optimizations for certain features, such as the const
keyword used here to declare variables.
Other Considerations:
Alternatives: If you're looking for alternative approaches to remove unwanted characters from a URL string, consider using:
url-decode
or decoded-url
, which can handle more complex URL decodings and sanitization.string-replace
or replace-string
, which offer more advanced features for character removal and manipulation.Keep in mind that the choice of approach depends on your specific use case, performance requirements, and personal preference.