[linux-audio-dev] [ot] [rant] gcc, you let me down one time too many

Simon Jenkins sjenkins at blueyonder.co.uk
Wed Jun 8 08:50:42 UTC 2005


On Tue, 2005-06-07 at 19:34 -0500, Jan Depner wrote:
> On Tue, 2005-06-07 at 19:20, Dave Robillard wrote:
> > "Premature optimization is the root of all evil".  Using C arrays and
> > strings for no reason when a much more robust higher level type would
> > suffice is /just as stupid/ as always using slow high-level operations
> > in time critical code.
> > 
> > It's like arguing about, say, assembly vs. perl.  Anyone who says one
> > side is (always) "better" is automatically wrong. :)
> > 
> True.  I usually try to use the right tool for the job.
> Unfortunately, with the data I work with, the right tool is almost
> always the fastest tool.
> 
You must be working with relatively large amounts of relatively simple
data then.

Suppose I sum a vector of 5 million integers and it takes 6 seconds. And
assume - (generously![1]) - that I switch to using an array and now it
only takes 1 second. Hmmm... a 6 * speedup! So I look to see where else
my code could benefit from this super performance boost.

Aha! Here's a vector of 5,000 oscillator structures, and it takes 5
seconds to initialise them all. Switch to using an array and... erm...
now it only takes 4.995 seconds to initialise them all.

I'm sure my users will notice and appreciate the 5ms saving,  but I
suspect I could have served them better by looking at where my code was
actually spending most of its time before trying to "optimise" it.

Cheers

Simon

[1] It really was a generous assumption: I've assumed that arrays are
*infinitely* faster than vectors in this example.





More information about the Linux-audio-dev mailing list