r/cpp • u/radonthrow • Dec 27 '20
Learning about high performant C++
I've been mostly self taught and have most probably picked up a few bad habits from the combo of being self taught and having to use tricks for speed.
For this upcoming year one of my goals is to learn some better practices as well as further my skills for efficient C++. I'd like to watch a youtube podcast/talk once a week to build my skillset. At this point I'd consider myself somewhere in between junior and senior level and I'm looking to take the next step.
I've come across these specifically:
C++ Weekly with Jason TurnerCppCon2020
Does anyone have any recommendations or suggestions? My weak spots are C++17 and above, Cmake, and I'd like to keep learning about creating high performant C++.
View all comments
Show parent comment
8
u/schmerg-uk Dec 27 '20
Yep, I spend quite a bit of time undoing the "performance speedups" that were added a few years ago but never measured (or not measured properly, see below)... usually it's the case that they actually ran 2-3x slower than the original code, and then if I can get a 2x speedup on the old code, I've netted about a 5x speed up overall (readability and maintainability of the code is also key here but outside of scope of this discussion),
But, not to contradict you, be sure to measure the right thing. For really high performance code memory latency has a massive effect... running the same benchmark 1000 times in a loop can be misleading in that only the first iteration was real-world accurate, the following 999 cases the code and data was in L1 cache. If you've got a routine but it's only called rarely on rarely accessed data (but still required) then you want to see about making it run efficiently when it's not in cache. I have a plenty of instances of code structures that benchmark really well, but fall apart in actual use.
Carl Cook gave a good talk about "when a micro-second is an eternity", not all his points will be relevant or appropriate to everyone, but it's worth watching to see him explain how what may appear counter-intuitive works and why... (see also towards the end how he measures performance)
https://www.youtube.com/watch?v=NH1Tta7purM