Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
javascript replaceAt
(version: 2)
Comparing performance of:
Substr vs Array.from vs Array.split
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
// Set up const replaceAt = (str, index, character) => str.substr(0, index) + character + str.substr(index+character.length); const replaceAt2 = (str, index, character) => { const chars = Array.from(str); chars[index] = character; return chars.join(''); } const replaceAt3 = (str, index, character) => { const chars = str.split(''); chars[index] = character; return chars.join(''); } // Set up test variables const str = new Array(10000).fill('0123456789').join('0123456789');
Tests:
Substr
replaceAt(str, str.length / 2, "W");
Array.from
replaceAt2(str, str.length / 2, "W");
Array.split
replaceAt3(str, str.length / 2, "W");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Substr
Array.from
Array.split
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Substr
29616630.0 Ops/sec
Array.from
110.0 Ops/sec
Array.split
116.7 Ops/sec
Related benchmarks:
regexReplace vs arrayReplace
Battle of strings
Battle of strings
test-string
test-string2
temptest
replaceAll vs regex replace vs neu parser
Test AAAAA
javascript Trimming leading/trailing characters (with set trim)
Comments
Confirm delete:
Do you really want to delete benchmark?