Key ideas & timestamps
Timestamp links open the original conversation at that moment.
Data Structure Benchmarking Methodology
To test whether arrays are genuinely faster than linked lists, identical C programs were written to sum 125,000 structure elements stored consecutively in an array versus scattered across memory in a singly linked list. Both structures held an integer p and an integer q, with the linked list featuring an extra pointer to the next memory node. Running the code across multiple hardware platforms revealed counterintuitive performance differences driven by underlying hardware architecture rather than abstract algorithmic complexity.
Hardware Architecture and Caching Effects
CPU Caches Make Arrays Faster Than Linked Lists
On modern processors like the Raspberry Pi or Atari Falcon equipped with instruction and data caches, arrays significantly outperform linked lists during sequential traversal. Because array elements occupy a single continuous memory block, hardware prefetchers load cache lines efficiently, whereas linked lists require two separate memory fetches per node—one for the data value and another to follow the pointer to the next dispersed node.
THE TENSION
Cacheless CPUs Reverse Array And Linked List Performance
On legacy cacheless hardware like the original Atari ST utilizing an 8 MHz CPU, linked lists actually executed slightly faster than arrays during a full traversal test. Without a CPU cache, every memory fetch—whether for instructions, array data, or linked list pointers—must hit main memory at identical speeds. The slightly leaner layout on the cacheless machine gave the linked list a marginal timing advantage.
Compiler Optimization Impact
Compilers heavily influence benchmark outcomes by automatically restructuring high-level code during compilation. For instance, using the Clang C compiler on an iMac unrolled loops to process multiple array accesses simultaneously, reducing branching overhead and delivering execution speeds five times faster than basic compilation. This demonstrates that empirical performance depends heavily on compiler optimization strategies alongside raw hardware design.