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
This test case compares three alternative isFunction implementations:
isFunctionA checks the internal [[Class]] name of an object to determine if it is a function. Unfortunately, while this check is the most reliable, it's also less efficient due to the extra call to Object#toString.isFunctionB was proposed as an alternative to the typeof and instanceof operators by Garrett Smith. This implementation uses duck-typing, so it may produce incorrect results.isFunctionC is currently used in Underscore.js. This implementation uses only basic duck-typing; thus, it is the most likely to produce incorrect results.<script>
var getClass = {}.toString,
hasProperty = {}.hasOwnProperty,
expression = /Kit/g;
function Test() {}
// Checks the internal [[Class]] name of the object.
function isFunctionA(object) {
return object && getClass.call(object) == '[object Function]';
}
// Partial duck-typing implementation by Garrett Smith.
function isFunctionB(object) {
if (typeof object != 'function') return false;
var parent = object.constructor && object.constructor.prototype;
return parent && hasProperty.call(parent, 'call');
}
// Pure duck-typing implementation taken from Underscore.js.
function isFunctionC(object) {
return !!(object && object.constructor && object.call && object.apply);
}
//Typeof
function isFunctionD(object) {
return (typeof object === "function")
}
function isFunctionE(object) {
return object && object instanceof Function;
}
</script>Ready to run.
| Test | Ops/sec | |
|---|---|---|
| isFunctionA | | ready |
| isFunctionB | | ready |
| isFunctionC | | ready |
| isFunctionD | | ready |
| "isFunctionE" | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.