Number() vs parseInt() vs plus vs bitwise (v74)

Revision 74 of this benchmark created by Salvo on


Setup

function CalcClass() {}
    
    CalcClass.prototype.parseNumber = function(str) {
      return Number(str);
    };
    
    CalcClass.prototype.parseToInt = function(str) {
      return parseInt(str);
    };
    
    CalcClass.prototype.parsePlus = function(str) {
      return +str;
    };
    
    CalcClass.prototype.parseBitwise = function(str) {
      return str >> 0;
    };
    
    CalcClass.prototype.parseMultiply = function(str) {
      return str * 1;
    };
    
    
    CalcClass.prototype.parseBitwiseNot = function(str) {
      return~~ str;
    };
    
    CalcClass.prototype.parseToIntBase10 = function(str) {
      return parseInt(str, 10);
    };
    
    CalcClass.prototype.parseBitwiseOr = function(str) {
      return str | 0;
    };
    
    CalcClass.prototype.parseMinus = function(str) {
      return str - 0;
    };
    
    var calc = new CalcClass();

Test runner

Ready to run.

Testing in
TestOps/sec
Number Constructor
calc.parseNumber('123456');
calc.parseNumber('123abc');
ready
parseInt
calc.parseToInt('123456');
calc.parseToInt('123abc');
ready
Plus operator
calc.parsePlus('123456');
calc.parsePlus('123abc');
ready
Bitwise >> (right shift)
calc.parseBitwise('123456');
calc.parseBitwise('123abc');
ready
Multiply (force cast)
calc.parseMultiply('123456');
calc.parseMultiply('123abc');
ready
Bitwise NOT
calc.parseBitwiseNot('123456');
calc.parseBitwiseNot('123abc');
ready
parseInt with base argument
calc.parseToIntBase10('123456');
calc.parseToIntBase10('123abc');
ready
Bitwise OR
calc.parseBitwiseOr('123456');
calc.parseBitwiseOr('123abc');
ready
minus 0
calc.parseMinus('123456');
calc.parseMinus('123abc');
ready

Revisions

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