native isFinite vs lodash isFinite vs jQuery isNumeric

Benchmark created by dwelle on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js">
</script>

Setup

var a = [NaN, 42, new Number(3), Infinity, -Infinity, -3, 0, new Boolean(false), null, undefined, [], {}, function() {}, /z/, false, true, '', 'a',  new Date()];
    
    function customIsFinite ( num ) {
      if (
        Object.prototype.toString.call( num ) === '[object Number]' &&
        num === num &&
        num > -Infinity &&
        num < Infinity
      ) return true;
      return false;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
native Number.isFinite
a.forEach(function( el ) {
  return Number.isFinite( el );
});
ready
lodash isFinite
a.forEach(function( el ) {
  return _.isFinite( el );
});
ready
jQuery isNumeric
a.forEach(function( el ) {
  return $.isNumeric( el );
});
ready
custom isFinite
a.forEach(function( el ) {
  return customIsFinite( el );
});
ready

Revisions

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

  • Revision 1: published by dwelle on