array vs linked list: search

Benchmark publishedon

Setup

const N = 10000;

class Node {
  constructor(val) {
    this.val = val;
    this.next = null;
    this.prev = null;
  }
}

function buildDoublyList(n) {
  let head = new Node(0);
  let curr = head;

  for (let i = 1; i < n; i++) {
    const node = new Node(i);
    curr.next = node;
    node.prev = curr;
    curr = node;
  }

  return {
    head,
    tail: curr
  };
}

// init list
let { head: list, tail } = buildDoublyList(N);

// array để so sánh
let arr = [];
for (let i = 0; i < N; i++) arr.push(i);

Test Runner

Initializing...

Testing in
Test CaseOps/sec
array
arr.includes(N - 1);
ready
Llist
let curr = list;
while (curr && curr.val !== N - 1) {
  curr = curr.next;
}
ready

Revisions

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

Revision 1
publishedon