[] vs Array for object conversion
JavaScript performance comparison
Info
I was wondering: “What’s the performance overhead of using [].prototype instead of Array.prototype while converting object into array?”.
It seems logic that Array.prototype will be more performant than [].prototype because [].prototype will instantiate an Array on every call.
In fact, the results are very similar and close for Firefox/Safari/Webkit. But Chrome is way more efficient with Array.prototype.
Preparation code
<script>
unshift.apply({}, 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'.split(' '));
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Array.protoype |
|
pending… |
[].prototype |
|
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 FGRibreau
- Revision 2: published by Robert K
- Revision 7: published by Leonardo Dutra
0 comments