Comment

Comment by TheOtherHobbes

No, memory reads do not depend on the address distance, unless you create a list.

Ordinary memory is not a list. It's a flat space read in O(1).

In theory. In practice there are multiple levels of cache, and cached reads will be much, much faster than main memory reads.

So if your entire data structure lives in cache and you repeatedly loop through it, it's going to be processed much more quickly than a bigger and more spread-out structure.

There's also paging, and alloc/dealloc to consider, and maybe garbage collection.

By the time you include all of that big-O estimates can become wildly misleading generalisations, unless your n is always >a million or so.

For small n it can be way off.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton