I am comparing the performance between these 2 blocks of code:
Block 1
for(var i = 0; i < 20000; i++) {
let a = "a random string";
a.split("");
}
and Block 2
for(var i = 0; i < 20000; i++) {
let a = new nativeWindow.String("a random string");
a.split("");
}
According to this page test https://jsben.ch/Nzfb1 the first block is 50 percent faster.
But I still need to use block2 because I don't want the literal string to autobox to the window.String constructor, I'd like it to autobox to the constructor I define.
Is it possible to achieve this ?