Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ node_js:
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
24 changes: 22 additions & 2 deletions bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const values = [
];

suite
.add('current', () => values.forEach(v => current(v)))
.add('twoTypeof (current)', () => values.forEach(v => twoTypeof(v)))
.add('oneTypeof', () => values.forEach(v => oneTypeof(v)))
.add('oneLiner', () => values.forEach(v => oneLiner(v)))
.add('twoLiner', () => values.forEach(v => twoLiner(v)))
.add('if', () => values.forEach(v => isPrimitiveIf(v)))
.add('negation', () => values.forEach(v => negation(v)))
.add('equals', () => values.forEach(v => isPrimitiveEquals(v)))
Expand All @@ -38,13 +41,30 @@ suite
})
.run();

function current(val) {
function oneTypeof(val) {
const type = typeof val
if (type === 'object') {
return val === null;
}
return type !== 'function';
}

function twoTypeof(val) {
if (typeof val === 'object') {
return val === null;
}
return typeof val !== 'function';
}

function oneLiner(val) {
return typeof val === 'object' ? val === null : typeof val !== 'function'
}

function twoLiner(val) {
const type = typeof val
return type === 'object' ? val === null : type !== 'function'
}

function negation(val) {
if (val === null) {
return true;
Expand Down