type checking

Benchmark created on


Setup

var s = "";
var n = 0;
var b = false;
var a = [];
var o = {};
var u = undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
typeof operator, literal equality
if (typeof o === 'boolean') {
	
} else if (typeof o === 'string') {
	
} else if (typeof o === 'undefined') {
	
} else if (typeof o === 'function') {
	
} else if (typeof o === 'number') {
	
} else {
	n += 1;
}
ready
switch with stored value
const t = typeof o;

switch (t) {
	case 'boolean':
		break;
	case 'string':
		break;	
	case 'undefined':
		break;	
	case 'function':
		break;	
	case 'number':
		break;		
	default:
		n += 1;
}
ready

Revisions

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