[GTALUG] Idiomatic programming versus micro-optimizations
David Mason
dmason at ryerson.ca
Fri Apr 9 12:52:41 EDT 2021
On Apr 9, 2021, 11:51 AM -0400, Len Sorensen via <talk at gtalug.org>, wrote:
> But using a loop means you are telling the system how to do things,
> rather than telling it what you want done and letting it (usually) do
> a better job at the how. After all with a loop you are controlling the
> excution order of the processing. If done right you usually shouldn't
> need to care.
Another fine example of this is with Rust where you can write very natural, idiomatic, safe, code and then trust the compiler to mostly optimize most perceived overhead away. In fact there are often optimizations that Rust can do that C compilers can’t do.
Here is a very interesting series of articles where someone takes a heavily optimized C program, converts it to Rust - with progressively more idiomatic versions, and ends up with a Rust program 3% faster than C (clang) and 20% faster than C (gcc), then rewrites it using the natural Rust iterators rather than indexing loops and it’s now 27% faster than clang!! http://cliffle.com/p/dangerust/
> But yes functional languages require a different philosophy. Functional
> languages are not for people that want to micromanage the computer.
The point is, apart from academic exercises, the percentage of people who *need* to micromanage the computer is getting vanishingly small. I would say measured in the low thousands, but hundreds is probably more accurate. Unless you’re writing a compiler, interpreter or for an application where the computer has to add no more than $0.25 to the cost of the product, you really shouldn’t care.
It really is time for C to go away! But TIOBE doesn’t agree https://www.tiobe.com/tiobe-index/ with C back to #1 and assemble up to #14!!!! (While Rust is #29) Just shows how important my opinion is!!
../Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/talk/attachments/20210409/141f23c4/attachment.html>
More information about the talk
mailing list