Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Linked list is not faster than array! It was benchmarked incorrectly. #4

Closed
eldargab opened this Issue · 0 comments

2 participants

@eldargab

I tested linked list's performance more carefully and published results. It turned out that it's not faster.

So why there is 2 times gain in the fast-lists's benchmark:

for (var j = 0; j < l; j ++) {
  if (j % 2) list.push(j)
  else list.unshift(j)
}
for (var j = 0; j < l; j ++) {
   if (j % 2) list.shift(j)
   else list.pop(j)
}

That's because it fills list with both unshift() and push() as well as removes with both pop() and shift(). While pushes - pops of native Array are very fast, shifts - unshifts are slow. But for stacking we are doing only pushes and pops, for queueing - pushes and shifts. Linked list perfoms equally for add - remove operations on both sides. So, while benchmark above is correct for testing linked list's performance it depreciates array results.

@isaacs isaacs closed this in a240b4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.