Array vs LinkedList

Benchmark created by wcj3 on


Setup

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();

Test runner

Ready to run.

Testing in
TestOps/sec
Big Array
const arr = [];
for (let i = 0; i < 100000; i++){
arr.splice(0,0,i);
}
ready
Big LinkedList
for (let i = 0; i < 100000; i++){
link.append(i);
}
ready
Small LinkedList
for (let i = 0; i < 10; i++){
link2.append(i);
}
ready
Small Array
const arr = [];
for (let i = 0; i < 10; i++){
arr.splice(0,0,i);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.