Object.keys vs _,keys vs hasOwnProperty (v50)

Revision 50 of this benchmark created on


Preparation HTML

<script src="http://underscorejs.org/underscore-min.js"></script>

Setup

var i;
    var key;
    var keys;
    var l;
    var value;
    var hasOwnProperty = {}.hasOwnProperty;
    var obj = {
      'a': 1,
      'b': 2,
      'c': 3,
      'd': 4,
      'e': 5,
      'f': 6,
      'g': 7,
      'h': 8,
      'i': 9,
      'j': 10
    };
    keys = Object.keys(obj);

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
if (obj.hasOwnProperty('j')) {
	obj.hasOwnProperty('k');
}
ready
in Object.keys
if( 'j' in Object.keys(obj)) {
	'k' in Object.keys(obj);
}
ready
cached in Object.keys
if( 'j' in keys) {
	'k' in keys;
}
ready

Revisions

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