Results show operations per second (greater is better).
To run the benchmark yourself please see ./benchmark.
Printf Cheatsheet
// %c characterprintf('%c', 'b');// => 'c'// %C converts to uppercase character (if not already)printf('%C', 'b');// => 'B'// %d decimal integer (base 10)printf('%d', 100);// => '100'// %0Xd zero-fill for X digitsprintf('%05d', 1);// => '00001'// %Xd right justify for X digitsprintf('%5d', 1);// => ' 1'// %-Xd left justify for X digitsprintf('%-5d', 1);
,
'bar'
));
fast-printf
78,068,540
11,820,632
2,552,386
// => '1 '
// %+d adds plus sign(+) to positive integers, minus sign for negative integers(-)
printf('%+5d', 1);
// => ' +1'
printf('%+5d', -1);
// => ' -1'
// %e scientific notation
printf('%e', 52.8);
// => '5.28e+1'
// %E scientific notation with a capital 'E'
printf('%E', 52.8);
// => '5.28E+1'
// %f floating-point number
printf('%f', 52.8);
// => '52.8'
// %.Yf prints Y positions after decimal
printf('%.1f', 1.234);
// => '1.2'
// %Xf takes up X spaces
printf('%5f', 123);
// => ' 123'
// %0X.Yf zero-fills
printf('%05.1f', 1.234);
// => '001.2'
// %-X.Yf left justifies
printf('%-5.1f', 1.234);
// => '1.2 '
// %i integer (base 10)
printf('%i', 123);
// => '123'
// %b converts to boolean
printf('%b', true);
// => 'true'
printf('%b', 'true');
// => 'true'
printf('%b', 1);
// => 'true'
// %B converts to uppercase boolean
printf('%b', true);
// => 'TRUE'
printf('%b', 'true');
// => 'TRUE'
printf('%b', 1);
// => 'TRUE'
// %o octal number (base 8)
printf('%o', 8);
// => '10'
// %s a string of characters
printf('%s', 'foo');
// => 'foo'
// %Xs formats string for a minimum of X spaces
printf('%5s', 'foo');
// => ' foo'
// %-Xs left justify
printf('%-5s', 'foo');
// => 'foo '
// %S converts to a string of uppercase characters (if not already)