Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
replaceAT
(version: 1)
Comparing performance of:
Substr vs Array.from vs Str.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");
Str.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
Str.split
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.2.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Substr
32080596.0 Ops/sec
Array.from
223.0 Ops/sec
Str.split
295.2 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?