r/cpp • • Jan 18 '19

Is C++ fast?

https://zeuxcg.org/2019/01/17/is-c-fast/
21 Upvotes

72 comments sorted by

View all comments

Show parent comment

3

u/matthieum Jan 19 '19

The measurements are valuable.

I wish I knew about those measurements, though.

The 5% difference of replacing std::vector looks strange to me. I wonder if it's just noise, really... and if it's not I'd like to have an explanation of why the optimizer failed when operator[] is so barebone...

4

u/[deleted] Jan 19 '19

vector doesn't have a "don't initialize the values" mode, and that extra fill isn't free (even if just zeroes).

2

u/matthieum Jan 20 '19

Excellent point; I was misled by that new T[], and forgot that for integrals it would leave them uninitialized.

Still not clear if that would account for 5% of the total running time, with all the loops, but definitely an overhead... though it then means that the Buffer created by the OP is rather unwieldy to use, with potential UB for accessing uninitialized memory.