type checking (v2)

Revision 2 of this 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
if statements, repeated 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
if statements, stored typeof, literal equality
const t = typeof o;

if (t === 'boolean') {
	
} else if (t === 'string') {
	
} else if (t === 'undefined') {
	
} else if (t === 'function') {
	
} else if (t === '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
switch with inline value
switch (typeof o) {
	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.