Insert char at given position in string (v3)

Revision 3 of this benchmark created by simnalamburt on


Description

It is cheaper to insert chart at given position using substr and + or it is better to split the string, splice it and then join?

Setup

var content = 'This is my string, which is that long';

Test runner

Ready to run.

Testing in
TestOps/sec
slice, concat
content.slice(0, 18) + '$' + content.slice(18);
ready
substr, concat
content.substr(0, 18) + '$' + content.substr(18);
ready
substring, concat
content.substring(0, 18) + '$' + content.substring(18);
ready
split, splice, join
var arr = content.split('');
arr.splice(18, 0, '$');
arr.join('');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.