Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex vs string replaceAll
(version: 1)
Comparing regex vs string versions of replaceAll
Comparing performance of:
regex vs string
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var str = 'Hello {first} {last}. Your first name is {first} and last name is {last}.'
Tests:
regex
str = str.replaceAll(new RegExp('{first}', 'g'), 'John') str = str.replaceAll(new RegExp('{last}', 'g'), 'Doe')
string
str = str.replaceAll('{first}', 'John') str = str.replaceAll('{last}', 'Doe')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regex
string
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0
Browser/OS:
Firefox 144 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regex
5991582.5 Ops/sec
string
21371256.0 Ops/sec
Related benchmarks:
Single vs multiple regex replace calls
compare string replace all RegExp and split + join and replace
Regex vs split/join on replacing empty spaces
Replace Comparison
regex vs double replace vs substring
String replace using regex vs string
replaceAll vs regex replace string
RegEx.test vs. String.includes vs. String.match vs String.replace
RegEx.test vs. String.includes vs. String.match vs String.replace vs String.replace classic
Comments
Confirm delete:
Do you really want to delete benchmark?