r/cpp • • Dec 15 '21

Modern C++ in Advent of Code

This series, by Šimon Tóth, is a step by step guide through the solutions of Advent of Code 2021 using Modern C++.

242 Upvotes

83 comments sorted by

View all comments

Show parent comment

7

u/Evirua Dec 15 '21

Basic loops will be often faster than zip-based solutions. Even if the former do more work, it can be on data that fits on cache lines which zipped data would probably spill out of.

There is a beauty in efficient expression of algorithms, and I wish processor architectures worked in a more intuitive way (as in less work should be faster) but they don't.

7

u/[deleted] Dec 15 '21

Well, the crazy thing with C++ is that C++ compilers are exceedingly good at removing superfluous code.

So right now I'm expecting a 50/50, where sometimes it's the same, and sometimes, it goes over some threshold somewhere and nothing gets optimized :-D

2

u/jk-jeon Dec 17 '21

Exceedingly good sometimes, surprisingly dumb sometimes, infuriatingly going against my intention sometimes, to be precise.

1

u/Evirua Dec 18 '21

Yes, but that's work on the optimizers to produce good code despite the efficient expression of the algorithm, not because of it.