Left zero filling (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
var pad = 20;
var n = 3000;
</script>

Setup

var s = String(n);

Test runner

Ready to run.

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

ready
for loop
for(;s.length < pad; s='0'+s);
ready

Revisions

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