Comment by facepalm 11 years ago What I don't get about Left-Pad, shouldn't they have used Arrays.join for better perormance? 2 comments facepalm Reply richmarr 11 years ago Array performance isn't always better than string concatenation.In this test case it comes out slower: https://jsperf.com/left-pad-arrays/3But ultimately it doesn't matter in the least for 99.9% of use cases:https://blog.codinghorror.com/the-sad-tragedy-of-micro-optim... facepalm 11 years ago Interesting - well I thought if it is being used by thousands of libraries it might be worth optimizing.I just tried in NodeJS, you could also just instantiate an Array of a given length and join it with spaces, like this.var x = new Array(5);x[4] = "abc";x.join(" ");No idea if it could be faster - but the test you linked to pushes spaces into the Array.
richmarr 11 years ago Array performance isn't always better than string concatenation.In this test case it comes out slower: https://jsperf.com/left-pad-arrays/3But ultimately it doesn't matter in the least for 99.9% of use cases:https://blog.codinghorror.com/the-sad-tragedy-of-micro-optim... facepalm 11 years ago Interesting - well I thought if it is being used by thousands of libraries it might be worth optimizing.I just tried in NodeJS, you could also just instantiate an Array of a given length and join it with spaces, like this.var x = new Array(5);x[4] = "abc";x.join(" ");No idea if it could be faster - but the test you linked to pushes spaces into the Array.
facepalm 11 years ago Interesting - well I thought if it is being used by thousands of libraries it might be worth optimizing.I just tried in NodeJS, you could also just instantiate an Array of a given length and join it with spaces, like this.var x = new Array(5);x[4] = "abc";x.join(" ");No idea if it could be faster - but the test you linked to pushes spaces into the Array.
Array performance isn't always better than string concatenation.
In this test case it comes out slower: https://jsperf.com/left-pad-arrays/3
But ultimately it doesn't matter in the least for 99.9% of use cases:
https://blog.codinghorror.com/the-sad-tragedy-of-micro-optim...
Interesting - well I thought if it is being used by thousands of libraries it might be worth optimizing.
I just tried in NodeJS, you could also just instantiate an Array of a given length and join it with spaces, like this.
var x = new Array(5);x[4] = "abc";x.join(" ");
No idea if it could be faster - but the test you linked to pushes spaces into the Array.