Re: Bug/Gross InEfficiency in HeathField's fgetline program



Antoninus Twink said:

On 9 Oct 2007 at 9:34, Richard Heathfield wrote:

<snip>

So in this case, the performance increase is meaningless, whereas the
loss of clarity is significant.

But exactly the opposite is true - clarity is lost in *your* version, by
taking something simple and making a meal of it.

Clearly, you are entitled to your opinion. Equally clearly, many here do
not share it, including me.

<snip>

It's terribly, terribly simple C. It's astoundingly easy for most C
people. I simply cannot understand why you would find it difficult or
complex.

Yes, it's terribly, terribly simple. Almost babyish even. I did not mean
that your *code* is complex, but that the *algorithm* is complex.

You're kidding, right? If you think that's a complex algorithm, steer well
clear of Miller-Rabin or Boyer-Moore (or, come to that, gcd).

And
you will say, "But it's a simple algorithm!" Right, it isn't complex by
any objective standard of complexity, but it's *more complex than it
needs to be* - why swap a simple single-pass algorithm for a 2-pass
algorithm?

I didn't swap anything. I just followed my programming instincts. It was a
long time ago, but I expect I reasoned roughly along these lines: (a) the
original might not be writeable, so make a safe copy; (b) hack the copy,
leaving the original alone.

During development, I would certainly have noticed if the performance were
unacceptable (because I tend to develop incrementally most of the time, so
sudden performance drops will normally stand out), and done something
about it. Since that never happened, I didn't bother. This is in full
accordance with the Two Rules of Optimisation.

And if you make simple things over-complicated, we might not
unreasonably suspect that you might make complicated things into a
complete mess.

You might think that my way is more complicated, and that's entirely up to
you. But John Bode's optimiser clearly disagrees with you.

By the way: if, for the sake of argument, we accept that my code /is/
grossly inefficient, how should we describe your code, which - on John's
system - is between 20% and 85% *slower* than mine?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.