News for hackers. Stuff that matters.
Re:Writing a custom iterator in modern C++ by robscallsign on Sunday December 20, 2020 @09:52PM (#25491707)
Keep in mind that most of the details you mentioned are for the developer of the library, not the end user/consumer of the library.

Ultimately most consumers of the library care if they can call std::sort(YourSpecialContainer.begin(), YourSpecialContainer.end()); in a consistent manner with some semblance that the use of templates and interfaces result in nearly zero overhead of the abstraction.

Re:Writing a custom iterator in modern C++ by vardump on Monday December 21, 2020 @03:41AM (#25493180)
"nearly zero overhead"

I can't call anything "nearly zero overhead" that can generate large amounts of code. Not at least with a pure conscience.

I've seen enough many cases of better performance with more "overhead" but drastically smaller code size.

Re:Writing a custom iterator in modern C++ by flqn on Monday December 21, 2020 @11:47AM (#25496623)
Code size is not always a good performance metric
Re:Writing a custom iterator in modern C++ by vardump on Monday December 21, 2020 @11:49AM (#25496653)
Nothing is a good performance metric apart from profiling. Preferably with runtime conditions (CPU load, memory bandwidth, etc.) closely mirroring production setting(s).

It's very easy to forget things like memory bandwidth, inter-core/CPU links, etc. are all limited resources. And that on real systems resources are shared.

Re:Writing a custom iterator in modern C++ by benibela on Monday December 21, 2020 @01:57PM (#25498112)
I usually profile everything with valgrind callgrind
Re:Writing a custom iterator in modern C++ by benibela on Monday December 21, 2020 @10:34AM (#25495813)
Usually people say std::sort is faster than qsort
Re:Writing a custom iterator in modern C++ by vardump on Monday December 21, 2020 @11:46AM (#25496604)
It's true whenever the function call overhead for the comparison operation dominates. Inlining a trivial operation (often just one instruction) is one extreme.

At the other extreme L1C cache (typically just 32 kB) gets constantly trashed by numerous type specialized functions. Individually fast when microbenchmarked, but collectively slow.

That's why profiling is a must when high performance is required. Microbenchmarks can be very misleading.

Re:Writing a custom iterator in modern C++ by gpderetta on Tuesday December 22, 2020 @09:06AM (#25506362)
Why would all template specializations for be in L1?

Even assuming you actually have multiple specializations in the same binary, which is not a given, only the one being in use or that it will be used very soon will be in L1. Instruction cache prefetching is extremely effective.

Re:Writing a custom iterator in modern C++ by flqn on Monday December 21, 2020 @11:45AM (#25496601)
It is, since the compiler can inline the comparator.
Re:Writing a custom iterator in modern C++ by vardump on Monday December 21, 2020 @09:14AM (#25495085)
Sorry for answering my own reply.

Zero overhead cult is pretty strong. People should profile instead. Sigh.