is Boolean

Benchmark created on


Description

test if type is boolean

Preparation HTML


Setup

arr = [];
for( let i = 0; i < 1000000; i++ ){
	arr[i] = (Math.random()<0.5) ?
		(Math.random()<0.5) : // boolean
		(Math.random()); // number
}

Test runner

Ready to run.

Testing in
TestOps/sec
true || false
let b = 0;
let i = arr.length;
while( i-- ){
	let x = arr[i];
	if( x === true || x === false ) b += 1;
}
ready
typeof direct
let b = 0;
let i = arr.length;
while( i-- ){
	let x = arr[i];
	if( typeof(x) === 'boolean' ) b += 1;
}
ready
typeof ref
let b = 0;
let t = typeof(true);
let i = arr.length;
while( i-- ){
	let x = arr[i];
	if( typeof(x) === t ) b += 1;
}
ready
=== !!
let b = 0;
let i = arr.length;
while( i-- ){
	let x = arr[i];
	if( x === !!x ) b += 1;
}
ready

Revisions

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