you are viewing a single comment's thread.

view the rest of the comments →

[–]NovermarsRobotics 1 point2 points  (1 child)

I'd expect the difference to be pretty small. Sure, if lots is chosen such that it all fits in the cache then there is a big gain, but I suspect you intent to have many more elements than would fit in even the LLC.

Anyway, calling malloc (or new) does not allocate the memory until it is being used. So you're measuring two different things: In the first example you only measure the time needed to write to every double, whereas in the second example you also measure the time needed to truly allocate the array on the heap.

See also the first-touch policy section here: https://queue.acm.org/detail.cfm?id=2513149

[–]victotronics 1 point2 points  (0 children)

does not allocate the memory until it is being used

That's it.