isType Functions

JavaScript performance comparison

Test case created by Tomás

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var toString = Object.prototype.toString;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Object.prototype.toString
(function (obj) {
    return toString.call(obj) === '[object Object]';
}({}))
pending…
instanceof Object
(function (obj) {
    return obj instanceof Object && obj.constructor === Object;
}({}))
pending…
Array.prototype.toString
(function (arr) {
    return toString.call(arr) === '[object Array]';
}([]))
pending…
instanceof Array
(function (arr) {
    return arr instanceof Array && arr.constructor === Array;
}([]))
pending…
String.prototype.toString
(function (str) {
    return toString.call(str) === '[object String]';
}(''))
pending…
instanceof String
(function (str) {
    return str instanceof String && str.constructor === String;
}(''))
pending…
Number.prototype.toString
(function (num) {
    return toString.call(num) === '[object Number]';
}(1))
pending…
instanceof Number
(function (num) {
    return num instanceof String && num.constructor === Number;
}(1))
pending…
typeof String
(function (str) {
    return typeof str === 'string';
}(''))
pending…
typeof Number
(function (num) {
    return typeof num === 'number';
}(1))
pending…

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

Compare results of other browsers

0 comments

Add a comment