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
Go 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:
9 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
string
21.4M/s
regex
6.0M/s
View exact numbers
Test name
Executions per second
✓
string
21,371,256 Ops/sec
regex
5,991,582 Ops/sec
Related benchmarks
Single vs multiple regex replace calls
Replace Comparison
regex vs double replace vs substring
String replace using regex vs 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?