Underscore.js isType Alternatives (v7)

Revision 7 of this benchmark created by Shane O'Sullivan on


Preparation HTML

<script src="https://documentcloud.github.com/underscore/underscore.js"></script>

Setup

var $ = window.jQuery,
      _ = window._,
      array = [1, 2, 3],
      func  = function(){},
      string = "string",
      number = 101,
      date   = new Date,
      regexp = /regexp/i;
  
  function isFunction(obj) {
    return typeof obj === 'function';
  }
  
  function isString(obj) {
    return typeof obj === 'string';
  }
  
  function isNumber(obj) {
    return typeof obj === 'number';
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Current Implementation
_.isFunction(func);
_.isFunction(array);

_.isString(string);
_.isString(array);

_.isNumber(number);
_.isNumber(string);
ready
typeof
isFunction(func);
isFunction(array);

isString(string);
isString(array);

isNumber(number);
isNumber(string);
ready

Revisions

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

  • Revision 1: published by Jeremy Ashkenas on
  • Revision 4: published by Paul Miller on
  • Revision 5: published by John-David Dalton on
  • Revision 7: published by Shane O'Sullivan on
  • Revision 9: published on
  • Revision 10: published on
  • Revision 11: published by Jesús Germade on
  • Revision 12: published by test on
  • Revision 13: published by Dan on
  • Revision 14: published by Jesús Germade on
  • Revision 15: published by Jesús Germade on
  • Revision 16: published by Jesús Germade on
  • Revision 17: published by mingc on
  • Revision 18: published by Eldar Abusalimov on