Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test replace vs substring vs slice for removing + from phone number
(version: 1)
In Javascript
Comparing performance of:
Replace vs Substring vs Substring hardcoded vs Slice vs Slice hardcoded
Created:
one month ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var numOfStrings = 100000 var prefix = '+' var testStrings = [] function phones() { return Math.random() * (19999999999 - 10000000000) + 10000000000; } for (let i = 0; i < numOfStrings; i++) { testStrings.push(prefix + phones()) }
Tests:
Replace
testStrings.map(str => { return str.replace(/\D/g, ''); })
Substring
testStrings.map(str => { return str.substring(1, str.length) })
Substring hardcoded
testStrings.map(str => { return str.substring(1, 12) })
Slice
testStrings.map(str => { return str.slice(0, str.length) })
Slice hardcoded
testStrings.map(str => { return str.slice(0, 12) })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Replace
Substring
Substring hardcoded
Slice
Slice hardcoded
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Replace
142.8 Ops/sec
Substring
976.9 Ops/sec
Substring hardcoded
733.2 Ops/sec
Slice
1380.3 Ops/sec
Slice hardcoded
728.7 Ops/sec
Related benchmarks:
Number generator
Performance Test: substring vs substr vs slice vs replace last character
Replace text vs slice text
random12
substring vs slice
replace vs. slice
Test Replace vs Slice
string concat big string
Test replace vs substring vs slice for removing + from phone number - FIXED
Comments
Confirm delete:
Do you really want to delete benchmark?