Stack vs. Heap: The Nanosecond Speed Gap

Stack allocation is dramatically faster, typically taking around 1 nanosecond (a single CPU instruction), while heap allocation can range from 25 to 200 nanoseconds, or even hundreds of times longer. This difference is negligible for single allocations but becomes critical in tight loops with millions of allocations, turning microseconds into seconds.

Sources

Open the full topic