LinkedList

JavaScript performance comparison

Revision 5 of this test case created by Brian

Info

LinkedList in JS vs Array.

Preparation code

<script src="http://www.pachisystems.com/LinkedList.min.js" type="text/javascript">
</script>
<script>
Benchmark.prototype.setup = function() {
    var data = [];
    for (var i = 0; i < 1500; i++) {
      data.push(Math.random() * 1000);
    };
   
    var llist = new LinkedList();
    for (var i = 0; i < 1500; i++) {
      llist.add(Math.random() * 1000);
    };
   
    var sortFunction = function(a,b) {
      return a > b;
    };
};

Benchmark.prototype.teardown = function() {
    data = null;
    llist.clear();
};
</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
LinkedList Sort
llist.sort(sortFunction);
pending…
Array Sort
data.sort(sortFunction);
pending…
Linked List Sorted Add
llist.clear()
for(var i = 0; i < 1500; i++) {
    llist.sortedAdd(Math.random() * 1000,sortFunction);
}
pending…
Array add and sort
data = [];
for(var i = 0; i < 1500; i++) {
    data.push(Math.random() * 1000);
    data.sort(sortFunction);
}
pending…
Linked List Add Then Sort
llist.clear();
for(var i = 0; i < 1500; i++) {
    llist.add(Math.random() * 1000);
}
llist.sort(sortFunction);
pending…
Array add THEN sort
data = [];
for(var i = 0; i < 1500; i++) {
    data.push(Math.random() * 1000);
}
data.sort(sortFunction);
pending…
Linked List Full Traversal
var current = llist._head;
var previous,x;
while(current.next !== null) {
    x = current.data;
    current = current.next;
}
pending…
Array Full Traversal
for(var i = 0, len = data.length; i < len; i++) {
    x = data[i];
}
pending…
LinkedList Populate & Clear
llist.clear();
for(var i = 0; i < 1500; i++) {
    llist.add(Math.random() * 1000);
}
llist.clear();
pending…
Array Populate & Clear
data = [];
for(var i = 0; i < 1500; i++) {
    data.push(Math.random() * 1000);
}
data = [];
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