3 ms·
Once I was in a training session on C++ STL, and the instructor told us not to use vector at() method but instead check the size and handle out-of-bounds issues
by pquki4 2y ago
Once I was in a training session on C++ STL, and the instructor told us not to use vector at() method but instead check the size and handle out-of-bounds issues using something else, because exceptions are slow.
Coming from another language, this sounded wild to me. There is a perfectly fine API in the standard library that we choose not to use but instead reinvent the wheel because of an "implementation detail" of a compiler, something a beginner or even an intermediate level C++ developer is likely unaware of.
- pjmlp 2y agoUnfortunely C and C++ have too many folks that do performance analysis by gut feeling instead of using a profiler, many times asserting stuff that with modern hardware are completly irrelevant.
- pquki4 2y agoWould like to hear more about it. Are you saying this (using .at vs "manual error handling") is premature optimization that might not have any effect on modern hardware?
- pjmlp 2y agoI am saying any optimization that isn't guided by profiler results, rather what people say, is nonsense. When I started coding, my first computer was a Timex 2068, containing a Z80 running at 3.5 MHz, with 64 KB, 48 KB available for data, loading data by tape. The first computer where I was programming in C++, was a 386SX runnning at 20 Mhz (with a turbo button for 40 Mhz, yuupi!), 2 MB RAM (only accessible with extenders, otherwise 640 KB), 40 MB hard disk (later converted to about 80 MB thanks to disk compression tools of the day), with DR-DOS 5. My current phone, holds a Exynos 1280, with 2 cores at 2.4 GHz and 6 cores at 2.0GHz, with 8 GB RAM, and SSD storage. And my phone is a toy, when compared with what a standard desktop computer, or servers are capable of in 2024. Additionally all modern hardware architectures are NUMA, multi-core, hybrid with GPUs. So unless someone can really prove that their gut feeling is going to fail on the expected deployment hardware, really fail flat on the floor, like the execution deadline is 5 ms, and the application can't do less than 5 ms no matter what, they are needlessly cargo culting optimizations.