[] vs Array for object conversion

Benchmark created by FGRibreau on


Description

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 HTML

<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

Ready to run.

Testing in
TestOps/sec
Array.protoype
function unshift() {
 var args = Array.prototype.slice.call(arguments);
 args.unshift(this);
}
ready
[].prototype
function unshift() {
 var args = [].prototype.slice.call(arguments);
 args.unshift(this);
}
ready

Revisions

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

  • Revision 1: published by FGRibreau on
  • Revision 2: published by Robert K on
  • Revision 7: published by Leonardo Dutra on
  • Revision 9: published by ecmanaut on