Linked List vs Array Traversal
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var LinkedNode = function(item, prev, next) {
this.item = item;
this.prev = prev;
this.next = next;
};
var LinkedList = function(item) {
this.head = item ? new LinkedNode(item, null, null) : null;
this.last = this.head;
this.length = 0;
this.current;
};
LinkedList.prototype.add = function( item ) {
var node;
if( this.head === null ) {
node = this.head = new LinkedNode(item, null, null);
} else {
node = this.last.next = new LinkedNode(item, this.last, null);
}
this.length += 1;
this.last = node;
};
var list = new LinkedList();
var arry = [];
var i = 10000
while(i > 0) {
var _i = i--;
list.add(!!_i % 3 ? _i : "BOO!");
arry.push(!!_i % 3 ? _i : "BOO!");
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Linked List Traversal |
|
pending… |
Array Traversal |
|
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 Jim Cowart
- Revision 2: published by Jim Cowart
- Revision 3: published by Jim Cowart
- Revision 4: published by Jamie Hill
0 comments