Insert char at given position in string (v2)

Revision 2 of this benchmark created by JM 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
using substr and +
content.substring(0, 18) + "$" + content.substr(18);
ready
using 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.