Array vs LinkedList

JavaScript performance comparison

Test case created by wcj3

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  class LinkedList {
    constructor() {
      this.head = null;
      this.last = null;
    }
    append(a) {
      const b = new Node(a);
      if (this.head === null) {
        this.head = b;
        this.last = this.head;
      }
      const prev = this.last;
      prev.next = b;
      this.last = b;
    }
  }
  
  class Node {
    constructor(item) {
      this.item = item;
      this.next = null;
    }
  }
  
  
  const link = new LinkedList();
  const link2 = new LinkedList();

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Big Array
const arr = [];
for (let i = 0; i < 100000; i++){
arr.splice(0,0,i);
}
pending…
Big LinkedList
for (let i = 0; i < 100000; i++){
link.append(i);
}
pending…
Small LinkedList
for (let i = 0; i < 10; i++){
link2.append(i);
}
pending…
Small Array
const arr = [];
for (let i = 0; i < 10; i++){
arr.splice(0,0,i);
}
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.

0 Comments