Electronics > Microcontrollers

stdlib + MCU haters: std itoa() uses less resources!

<< < (37/37)


--- Quote from: SiliconWizard on June 12, 2023, 08:57:02 pm ---
--- Quote from: Nominal Animal on June 12, 2023, 08:49:33 pm ---Premature optimization, like trying to make the fastest atoi() you can before making sure it is a limiting bottleneck in your task at hand, is an extremely common mistake, especially among programmers without sufficiently wide experience: they spend a lot of time on "optimizing" something that has no effect on the end result, essentially wasting valuable time.  Most often, true optimization avoids having to do that thing altogether, and achieves an order of magnitude greater savings.

--- End quote ---

Yes, yes, and yes!

It's interesting to see many people navigating between these two extremes: either excessive optimization on unimportant stuff, or complete waste of resources to save a couple hours, or sometimes just actually minutes, of development time.

--- End quote ---

Small differences in execution time seldom make any difference, but still you do't want to needlessly pessimise things.

Code size, on the other hand, is an absolute that is easy to measure and often leads to second order speedups.

I can't believe how many people just throw -O3 at everything, often bloating code size by factors, for very little speed gain over -O1. And making caches that much less effective when you start measuring the whole program, not just that one function in isolation.

Nominal Animal:
Another related detail is that code you intend to be temporary, often isn't.

My own criteria is "Will I curse myself, if I have to come back and maintain/modify this code after a year, after I've forgotten all the relevant details?"
It also reminds me to write comments that document my intent and the underlying idea or logic of the code; I want need those.

In the end optimisation is a bit of an art where you shouldn't lose sight of the big picture. Optimising a problem at the higher level by choosing the right algorithm is more effective than trying to optimise a randomly choosen algorithm. And there is also the factor of NRE costs. When I really need to optimise something (size / execution time), I do this to the level where it is enough. That will be the most cost effective solution. Unfortunately embedded programming is littered with dogmas that are supposed to be 'good generic rules' but more often than not lead to sub-optimal results for those who believe in these dogmas religiously.


--- Quote from: nctnico on June 12, 2023, 11:58:04 pm ---In the end optimisation is a bit of an art where you shouldn't lose sight of the big picture.

--- End quote ---
In a particular case, it is impossible to understand the meaning of the overall picture - because we are viewing a small part under a magnifying glass. Long consideration and discussion. So long - that the optimization process started naturally. (new version https://godbolt.org/z/bnfEbaxa1)

It is customary to draw the general picture without details, with a large wide brush. I'm talking about the general API of classical libraries created in the image and likeness of prehistoric dinosaurs. The main headache (which everyone stubbornly ignores) is operating with one character (letter, number) when printing or saving to a file. Cars used to be big and stupid, now they are small and very powerful. But the style has remained the same.
Stone that cannot be moved -> "printf()".


[0] Message Index

[*] Previous page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod