Checking types (v3)

Revision 3 of this benchmark created on


Description

How fast do checking types work?...

Setup

var str = "hello, world!";
var num = 503;
var obj = {hello: 'world'};
var arr = [obj, num, str];
var nll = null;

function isStrT(str){
	if(str == null) return false;
	return typeof str === 'string';
}
function isStrC(str){
	if(str == null) return false;
	return str.constructor === String;
}

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
var resultStr = str == null ? false : typeof str === 'string';
var resultNum = num  == null ? false : typeof num === 'string';
var resultObj = obj  == null ? false : typeof obj === 'string';
var resultArr = arr  == null ? false : typeof arr === 'string';
var resultNll = nll  == null ? false : typeof nll === 'string';
resultStr = str == null ? false : typeof str === 'string';
ready
constructor
var resultStr = str == null ? false : str.constructor === String;
var resultNum = num == null ? false : num.constructor === String;
var resultObj = obj == null ? false : 
 obj.constructor === String;
var resultArr = arr == null ? false :  arr.constructor === String;
var resultNll = nll == null ? false : nll.constructor === String;
resultStr = str.constructor === String;
ready
typeof FN
var resultStr = isStrT(str);
var resultNum = isStrT(num);
var resultObj = isStrT(obj);
var resultArr = isStrT(arr);
var resultNll = isStrT(nll);
resultStr = isStrT(str);
ready
constructor FN
var resultStr = isStrC(str);
var resultNum = isStrC(num);
var resultObj = isStrC(obj);
var resultArr = isStrC(arr);
var resultNll = isStrC(nll);
resultStr = isStrC(str);
ready

Revisions

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