Parsing vs Coercion (v2)

Revision 2 of this benchmark created by Adam Sanderson on


Setup

inputs = [
  '1', '2', '3', '4',
  '011', '09', '02', '08',
  ' 1', '  2 ', '', '  4',
  'x'
  ];

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt
for(var i=0; i < inputs.length; i++){ parseInt(inputs[i],10); }
ready
parseFloat
for(var i=0; i < inputs.length; i++){ parseFloat(inputs[i]); }
ready
Coerce
for(var i=0; i < inputs.length; i++){ +inputs[i]; }
ready
Bit Twiddle (|0)
for(var i=0; i < inputs.length; i++){ inputs[i] | 0; }
ready

Revisions

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

  • Revision 1: published by Adam Sanderson on
  • Revision 2: published by Adam Sanderson on