isArray vs. instanceof vs. {}.toString
JavaScript performance comparison
Preparation code
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script>
var isArray = Array.isArray;
var toString = {}.toString;
var a = [];
var b = [1, 2, 3];
var c = {};
var d = 'string';
var e = 2.3;
var f = undefined;
var g = null;
var h = new Date();
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
isArray |
|
pending… |
instanceof |
|
pending… |
toString() |
|
pending… |
underscore.isArray |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by knopsh
- Revision 2: published by Tobias Reiss
- Revision 3: published
- Revision 4: published
- Revision 5: published by alFReD NSH
0 comments