Linked List vs Array Traversal
JavaScript performance comparison
Preparation code
<script src="http://underscorejs.org/underscore.js"></script>
<script src="https://raw.github.com/postaljs/postal.js/master/lib/postal.js"></script>
<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 NO_OP = function() {};
var list = new LinkedList();
var arry = [];
var i = 200
while(i > 0) {
list.add(postal.subscribe({ channel: "channel" + i, topic: "topic." + i, callback: NO_OP }));
arry.push(postal.subscribe({ channel: "channel" + i, topic: "topic." + i, callback: NO_OP }));
i--;
}
};
</script>
Preparation code output
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