Parsing vs Coercion

JavaScript performance comparison

Test case created by Adam Sanderson

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  inputs = [
  '1', '2', '3', '4',
  '011', '09', '02', '08',
  ' 1', '  2 ', '', '  4',
  'x'
  ];

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
parseInt
for(var i=0; i < inputs.length; i++){ parseInt(inputs[i],10); }
pending…
parseFloat
for(var i=0; i < inputs.length; i++){ parseFloat(inputs[i]); }
pending…
Coerce
for(var i=0; i < inputs.length; i++){ +inputs[i]; }
pending…
Bit Twiddle (|0)
for(var i=0; i < inputs.length; i++){ inputs[i] | 0; }
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.

0 Comments