Prepend zero

JavaScript performance comparison

Test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Slice Without Zero
var x, y, string;
for( x = 1000; x > 0; x -= 1 ) {
    string = x.toString();
    y = ( '0' + string ).slice( -2 );
}
pending…
Slice With Zero
var x, y, string;
for( x = 1000; x > 0; x -= 1 ) {
    string = '0' + x.toString();
    y = ( '0' + string ).slice( -2 );
}
pending…
CharAt Ternary Without Zero
var x, y, string;
for( x = 1000; x > 0; x -= 1 ) {
    string = x.toString();
    y = ( 1 === string.length && string.charAt( 0 ) !== "0" ) ? '0' + string : string;
}
pending…
CharAt Ternary With Zero
var x, y, string;
for( x = 1000; x > 0; x -= 1 ) {
    string = '0' + x.toString();
    y = ( 1 === string.length && string.charAt( 0 ) !== "0" ) ? '0' + string : string;
}
pending…
ParseInt Binary Without Zero
var x, y, string, parsed;
for( x = 1000; x > 0; x -= 1 ) {
    string = x.toString();
    y = ( 1 === string.length && ( parseInt( string, 10 ).toString() === string ) ? '0' + string : string );
}
pending…
ParseInt Binary With Zero
var x, y, string, parsed;
for( x = 1000; x > 0; x -= 1 ) {
    string = '0' + x.toString();
    y = ( 1 === string.length && ( parseInt( string, 10 ).toString() === string ) ? '0' + string : string );
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment