-
-
Save bigopon/680c1d0d904fad05549ab93fa033897d 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('cache', function() { | |
function isObject(val) { | |
var type = typeof val; | |
return val && (type === 'function' || type === 'object'); | |
} | |
let i = tests.length; | |
while (i--) { | |
isObject(tests[i]); | |
} | |
}) | |
.add('no-cache', function() { | |
function isObject(val) { | |
return val && (typeof val === 'function' || typeof val === 'object'); | |
} | |
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