Number() vs parseInt() vs plus vs bitwise (v125)

Revision 125 of this benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

Setup

var valueString = "" + new Date().valueOf();
  
  console.log('Number', Number(valueString));
  console.log('parseInt', parseInt(valueString));
  console.log('parseInt, 10', parseInt(valueString, 10));
  console.log('plus', +valueString);
  console.log('bitwise', valueString >> 0);
  console.log('multiplie', valueString * 1)
  console.log('not not', ~~valueString)
  console.log('pipe 0', valueString | 0)

Test runner

Ready to run.

Testing in
TestOps/sec
lodash.parseInt
_.parseInt(valueString)
ready
lodash.toNumber
_.toNumber(valueString)
ready

Revisions

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