Linked list vs array

JavaScript performance comparison

Revision 6 of this test case created by tenbits

Preparation code

<script>
var Obj = function(a){ this.a = a; };
var SObj = function(a){ return {a:a, next: null}; };
var ProperObj = function(a){ this.a = a; this.next = null; };
</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
array
var arr = [];
arr.push(new Obj(1));
arr.push(new Obj(2));
arr.push(new Obj(3));
arr.push(new Obj(4));
arr.push(new Obj(5));
arr.push(new Obj(6));
arr.push(new Obj(7));
arr.push(new Obj(8));
arr.push(new Obj(9));
arr.push(new Obj(10));
 
pending…
List
var head = new Obj(1), o;
o = (head.next = new Obj(2));
o = (o.next = new Obj(3));
o = (o.next = new Obj(4));
o = (o.next = new Obj(5));
o = (o.next = new Obj(6));
o = (o.next = new Obj(7));
o = (o.next = new Obj(8));
o = (o.next = new Obj(9));
o = (o.next = new Obj(10));
pending…
Prevent Recreating of hidden class
var head = new ProperObj(1), o;
o = (head.next = new ProperObj(2));
o = (o.next = new ProperObj(3));
o = (o.next = new ProperObj(4));
o = (o.next = new ProperObj(5));
o = (o.next = new ProperObj(6));
o = (o.next = new ProperObj(7));
o = (o.next = new ProperObj(8));
o = (o.next = new ProperObj(9));
o = (o.next = new ProperObj(10));
pending…
inline objects
var head = SObj(1), o;
o = (head.next = SObj(2));
o = (o.next = SObj(3));
o = (o.next = SObj(4));
o = (o.next = SObj(5));
o = (o.next = SObj(6));
o = (o.next = SObj(7));
o = (o.next = SObj(8));
o = (o.next = SObj(9));
o = (o.next = SObj(10));
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:

0 comments

Add a comment