jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
/**
* Tells you the constructor (so basically the type) of the passed value
* @param {*} value
* @returns **String**, with first letter capitalized (e.g. "String","Object",...)
* @see [Erisan Olasheni](https://stackoverflow.com/a/51458052/20015615)
* @author bye-csavier
*/
function getType(x) {
/**
* about void 0 --> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void#description
* about (x!==x) --> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN#description
* about (x===x/0) --> https://stackoverflow.com/a/20608099
*/
return (x === null)? "Null" :
(x === void 0)? "Undefined" :
(x!==x)? "NaN" :
(x===1/0 || x===-1/0)? "Infinity" :
x.constructor.name;
}
let a = {ok:3}
let b;
Ready to run.
Test | Ops/sec | |
---|---|---|
getType() fn |
| ready |
typeof |
| ready |
direct use of x.constructor.name |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.