3 ms·
I'm surprised the version with pointers was only about 2x slower, not 10x slower as some people bashing Java often suggest. And this despite the fact that share
by pkolaczk 12y ago
I'm surprised the version with pointers was only about 2x slower, not 10x slower as some people bashing Java often suggest. And this despite the fact that shared_ptrs in C++ are generally heavier than references in Java/C#.
- ah- 12y agoI suspect this is because he only benchmarks small data sets, even the largest one used easily fits into the CPU cache. It would be interesting to see the number of cache misses for each benchmark, perf stat should be able to record that data. And even the shuffling doesn't really simulate a realistic distribution in memory, it'd be better to also allocate random memory block in between the objects.
- pkolaczk 12y agoAnd even if shuffling did that, comparisons to java still would be invalid, because Java has completely different algorithms for placing objects in memory which tend to bring referenced objects close to each other.
- Pxtl 12y agoThat was my reaction. I mean, let's think about all the overhead the shared_ptr adds: 1) Layer of indirection 2) Non-continuous memory 3) shared_ptr overhead itself as you mentioned. All that and only 2x slower? For many applications performance of this particular operation is a rounding error of a rounding error. This tells me not to worry about optimizing my iterations across datasets prematurely.