Last active
December 17, 2016 01:35
-
-
Save jdanyow/3608dfa47c23f359cb274606fa1e62f6 to your computer and use it in GitHub Desktop.
isObject bench
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function log(message) { | |
document.getElementById('status').textContent += message + '\n'; | |
} | |
log('running...'); | |
const tests = [ | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
null, undefined, 0, 1, true, false, '', 'adsfasf', new String('test'), {}, Object.create(null), Object.prototype, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, function() {}, | |
]; | |
// add tests | |
const suite = new Benchmark.Suite; | |
suite.add('strict', function() { | |
function isObject(val) { | |
return val !== null && (typeof val === 'function' || typeof val === 'object'); | |
} | |
let i = tests.length; | |
while (i--) { | |
isObject(tests[i]); | |
} | |
}) | |
.add('loose', function() { | |
function isObject(val) { | |
return val && (typeof val === 'function' || typeof val === 'object'); | |
} | |
let i = tests.length; | |
while (i--) { | |
isObject(tests[i]); | |
} | |
}) | |
.add('underscore', function() { | |
function isObject(val) { | |
var type = typeof obj; | |
return type === 'function' || type === 'object' && !!obj; | |
} | |
let i = tests.length; | |
while (i--) { | |
isObject(tests[i]); | |
} | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
log(String(event.target)); | |
}) | |
.on('complete', function() { | |
log('Fastest is: ' + this.filter('fastest').map('name')); | |
}) | |
// run async | |
.run({ 'async': true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>GistRun</title> | |
</head> | |
<body> | |
<pre><code id="status"></code></pre> | |
<script src="https://cdn.jsdelivr.net/g/[email protected],[email protected],[email protected]"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/node-uuid/1.4.7/uuid.js"></script> | |
<script src="bench.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment