Left zero filling (v2)

Revision 2 of this benchmark created by Fábio Miranda Costa on


Setup

var pad = 20;
    var n = 3000;

Test runner

Ready to run.

Testing in
TestOps/sec
Array.join
n = String(n);
new Array(pad - n.length + 1).join('0') + n;
ready
toFixed
(n / (Math.pow(10, pad))).toFixed(pad).substring(2);
ready
while loop
n = String(n);
while (n.length < pad) {
    n = '0' + n;
}

 
ready

Revisions

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