Faster for() loops? - Page 3

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: Faster for() loops?
Quoted text here. Click to load it

If saving 50 or even 100 machine code instructions saves you 10% of
memory then you only have space for 1000 instructions and would, in my
opinion, be better off programming in assembler where you actually have
control over what happens. Otherwise you might well find changes in the
compiler and library from version to version are more significant.

Quoted text here. Click to load it

<snip>

I would refer you to the above, but based on your response to Brian I'm
guessing that you have no consideration for other users of this group.
Don't be surprised if this leaves you with only the ignorant to talk to.
--
Flash Gordon
Living in interesting times.
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?
To Flash and Walter,

Maybe 10% saved for a 1k memory was a bit of an exageration on my part.

I'm currently working with some inhereted AVR GNU that was incomplete, by
quite some margin, yet close to the preferred memory limit with decent debug
info, and too big to feel comfortable without the debug.  Checking out the
size differences resulting from alternative ways of writing the same code
has resulted in a worthwhile amount of memory being recovered (I believe) -
i.e. I'm more relaxed about the situation now.  I'm telling the compiler to
optimise for size, since speed is not a problem.  Of course, if things won't
fit at the end, then I'll have to look for other optimisations, such as the
assembler suggested.  It's unlikely that I'll be forced to switch to a
different version of the compiler or libs.  Changing the code's architecture
and data structures results in bigger savings - I'm almost thru doing that
(for other reasons) and it looks like I'll recover over 1k of mem (out of
8k). and the resulting code is cleaner and easier to understand too.

You both probably know this through experience, but one trick I've found of
simply making a local copy of a global variable, that is used a fair bit in
a function, and then coping it back to the global afterwards saves a
reasonable amount of code size, over the more obvious code, that it makes
this particular trick worth knowing/trying when things do get tight - it's
obviously (to me now) a bigger saving if the global happens to be volatile
as well.

I have no personal problem trying these things out if it helps me to
understand what the compiler is likely to do with new code that I author
(afterall, it takes about 6 minutes to try a little trick out, which means
that it'll take about an hour to know 10 new things about the behaviour of
the compiler and to recognise oportunities, etc. in the future.)  Perhaps at
the end of the project, I would have had plenty of room anyway, but, as I
said things were tight, I was feeling uneasy, and every time I wanted more
debug info, it meant choosing something else for temporary culling which was
beginning to make things thorougly difficult.

Things seem to be going 'swimmingly' now - I hope that holds up to the end.


Quoted text here. Click to load it
can
Afterall, 50
I'm
found it



Re: Faster for() loops?
Quoted text here. Click to load it

If it's less then it is even less worth while.

<snip>

Quoted text here. Click to load it

Which just goes to show that you should concentrate on high level
optimisations not micro-optimisations.

Quoted text here. Click to load it

I've used processors where it would be one instruction to set up the
offset then another to read/write the value for a local as compared to
in the worst case a single instruction the same size as that pair of
instructions for a global. Of course, the compiler optimisations make
this irrelevant with most compilers since they will keep it in a
register if it is used much.

 > that it makes
Quoted text here. Click to load it

If it is volatile you are significantly changing the semantics, so
either the original code was wrong or your "optimised" code is wrong.

Quoted text here. Click to load it

All that you learn about micro-optimisation on one system you have to
forget on the next where your "optimisations" actually make it worse.
Also, if your optimisations make the code harder to read you have just
increased the cost to the company of maintenance, and since maintenance
is often a major part of the cost of SW over its lifetime this is not good.

 > Perhaps at
Quoted text here. Click to load it

It would almost certainly have saved you time and effort to restructure
the code and optimise the algorithms first (which you say you are doing)
since then you would not have found the need for "temporary culling"
because you have already admitted that it is saving you a significant
amount.

Quoted text here. Click to load it

Not really. You included in your message that restructuring is saving
you a vast amount of space which is further evidence that you should
always start at the algorithm and work down, not start with
micro-optimisation.


<snip>

For continual refusal to post properly despite being informed that top
posting is not accepted here...

*PLONK*
--
Flash Gordon
Living in interesting times.
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?

Quoted text here. Click to load it

If you say so.  It seems to me that I've just given myself a bit more memory
to play with in a tight situation.

Quoted text here. Click to load it
architecture
that
of

Yes, that's correct.  It does not mean, so-called micro-optimisations should
not be attempted.

Quoted text here. Click to load it
of
in

Well, in my case, GNU didn't seem to choose this optimisation - so, the
trick saved some bytes - that's indisputable, and as far as I can see, odd
that you'd want to dismiss the idea.

Quoted text here. Click to load it
it's
volatile

I don't think so.  The code is in an ISR.  While the ISR is running, the
global won't be changed externally.  The little trick saved something like
28 bytes and yet the global was only touched twice, if I remember correctly.

However, if someone has a counter example, I would be interested in knowing.

Quoted text here. Click to load it
means
of

Perhaps.  Yet, for very little effort, I have given myself more room to play
with in the current system, I've got a better feeling for the compiler's
quirks, and have saved (with just a few micro-optimisations) about 250-bytes
(out of 8k) - that's plenty more to extend an existing parameter look up
table built into the system in both directions (thus increasing the
versitility of the system), or to include more human-readable debug output
and even to use more sophisticated code for some other operations that are
yet to be written.  So, as far as I can see, I've gained by this exercise.
I've given myself an advantage, and you are still telling me it was next to
worthless because it comes under the lable 'micro-optimisation' or
'premature optimisation' - to me, it's just an achieved gain.

Quoted text here. Click to load it
good.

Errm, in this case, I don't think the code is harder to read - it's
straighforward C-code - nothing particularly difficult.  There are ample
comments documenting reasons for some of the slightly none-obvious ways of
doing something, along with the 'obvious' code snippet for ready-reference.
The code will go into a mass-produced product that is to be thorougly tested
before release - maintenance is not an option.

Quoted text here. Click to load it
I
more
was

I can't see this.  I've positively gained thru this exercise.  I have not
lost anything.

Quoted text here. Click to load it
end.

It looks like I will save about 1k with the restructure (but I cannot tell
for sure until I get the full re-structure into the embedded compiler - I'm
currently writing and testing the restructured part under Windows).  So, the
'micro-optimisations' would amount to another 25% on top of that - hardly a
worthless effort, wouln't you say.




Re: Faster for() loops?
On Wed, 28 Sep 2005 03:29:35 +0100, in comp.lang.c , "Joe Butler"

Quoted text here. Click to load it

Are you clinically thick? You're /still/ top posting. In CLC thats the
height of rudeness. Stop it.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?
Quoted text here. Click to load it

Who gives a shit? Why insult people over a minor matter of protocol? Sheesh!

Steve
http://www.fivetrees.com



Re: Faster for() loops?
On Thu, 29 Sep 2005 03:35:43 +0100, the renowned "Steve at fivetrees"

<comp.arch.embedded only>

Quoted text here. Click to load it

Hey, that's standard operating procedure over there at CLC.



Best regards,
Spehro Pefhany
--
"it's the network..."                          "The Journey is the reward"
snipped-for-privacy@interlog.com             Info for manufacturers: http://www.trexon.com
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?

Quoted text here. Click to load it


Don't disrespect our group wishes.

*plonk*



Brian


--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?
Quoted text here. Click to load it

Oh, so calling someone "clinically thick" over something so trivial is
somehow respectful?

Show some respect for others. *Then* you'd be entitled to talk to me on the
subject.

Steve
http://www.fivetrees.com



Re: Faster for() loops?
Quoted text here. Click to load it

I suggest you take a look at this thread to see what really happened.

Joe Butler was asked not to top-post.  He replied with a top-posted
followup.  Someone else again reminded him not to top-post.  His
and I quote, "prick." (and it was, of course, top-posted).

There are good reasons for our convention (here in comp.lang.c) of
discouraging top-posting; I won't repeat them here.  There are also
good reasons for not insulting people who are offering good advice.
If you've come into the middle of this discussion, it might not be
clear what's going on; groups.google.com can help you.

I suggest we drop this.  I don't believe there are any relevant points
that haven't already been made.

--
Keith Thompson (The_Other_Keith) snipped-for-privacy@mib.org  <http://www.ghoti.net/~kst
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?
Quoted text here. Click to load it

Ah. Mea culpa. If the disrespect I reacted to was in response to insulting
behaviour, then I apologise for leaping to the defence of the offender.

Quoted text here. Click to load it

Fully agreed.

FWIW: I understand and agree with the reasons for discouraging top-posting.
However I've grown far more tired of the flamefests that result from
top-posting than of top-posting itself. My patience ran out when I saw what
I thought was an over-the-top response. I was wrong; I apologise.

Steve
http://www.fivetrees.com



Re: Faster for() loops?
Let's put this into perspective.

Althought I don't know how to verify this, I suspect many 100s, perhaps
1000s, of people read these posts.

Only 2 or 3 people told me not to top post.  That's 3 out of 1000?  3 out of
10,000?  Who knows.  That suggests to me that the vast majority of people
don't give a damn.  Probably, like me, the vast majority are easily able to
deal with all the forms of posting and it is, therefore, not an issue for
them.

I understand that top-posting annoys some people.  For me, when someone
who's only contribution is to butt in with something along the lines of
"space corp. directive one ex delta nine has been violated", that is
infinitely more annoying than any other person's posting style.

The only input 'Default User' (prick) gave at that point was, "You need to
get the other point, the one about not top-posting".  If Default User had
any sense, he would have realised that I had chosen to ignore the advice
about top-posting, that it was not the first time that I had been told and,
therefore, it was a pretty pointless exercise to step in at that point.

Sincere regards to everyone.


Quoted text here. Click to load it
the
<http://www.ghoti.net/~kst
Quoted text here. Click to load it
<http://users.sdsc.edu/~kst
Quoted text here. Click to load it



Re: Faster for() loops?
Quoted text here. Click to load it

Don't know about majority, personally when I see a post that hard to
make sense of I'll just skip it and jump to next one...

Tom

top posting
Quoted text here. Click to load it
out of
people
to
for

Agreed. Life is too short to waste time un-mangling the conversation.

I have already kill-filed Joe Butler. (yes, I know that's is a rude thing to
say - it's part of my point, here) I have no idea how many more of the 100s
or 1000s who read c.a.e and c.l.c have also done so.

Oddly, the first post I see in this thread from him he has snipped and
bottom posted (unfortunately, without proper attribution for what he was
responding to). It is only his later posts that flaunt the etiquette of
these groups.

Bob



Re: Faster for() loops?
Quoted text here. Click to load it

Make that 4. I suspect that many others controlling themselves
and just waiting for this recurring flamefest to die.

Who knows why you cannot simply comply with the customs
of these groups. They are among the best usenet has to
offer.

<sigh>

--
Michael N. Moran           (h) 770 516 7918
5009 Old Field Ct.         (c) 678 521 5460
We've slightly trimmed the long signature. Click to see the full one.
Re: Faster for() loops?
Quoted text here. Click to load it

These groups have a high proportion of lurkers who seldom or never post,
a fair number who post semi-regularly, and a core who have been here for
years and contribute regularly for the benefit of all.  It's often these
core posters that ask for usenet rules of courtesy to be followed - they
put a lot of time and effort into helping people here, and all they ask
in return is a little politeness.  Personally, I can't see any reason
not to follow conventions - you say you understand that top-posting
annoys people, yet you continue to do it.

Quoted text here. Click to load it

Since you seem to have lost track of the history here, I'll summarise
it.  A poster ("Flash Gordon") replied to your post with useful
information, along with a request that you follow usenet conventions to
make the thread easier for everyone.  It's only when you completely
ignored that request that you got a curt reply - and you responded with
a personal insult.  That's what got this thread rolling.

If you are on the phone to someone, and they ask you to speak a bit
louder, would you ignore the request?  If they asked you a second time,
would you call them a "prick" ?  If you are visiting someone's house, do
you put your feet on the table just because you do it at home?  Or do
you light up a cigarette without asking, because that's your "personal
style" ?  No, any time you interact with other people, you are polite
and respectful, and follow the conventions already established.  Usenet
is nothing special in this regard.

Re: Faster for() loops?
On 30 Sep 2005 10:02:31 +0200, David Brown

Quoted text here. Click to load it

Conventions are standards that are agreed to by all or most of the
participants.  The prohibition against top-posting is not one of them,
except in the mind of a few zelots.  You are free to express your
opinion that you think top-posting is impolite, but when you try to
assign any authority to that opinion, don't be surprised if someone
like me calls you on it.

Quoted text here. Click to load it

All these analogies are of one-on-one interactions.  Usenet involves
many-to-one interactions.  One person's request for what he thinks is
politeness has to be weighed with what others in the group think.
Just because one person is pissed whenever he sees top-posting that
does not mean everyone in the group, or even a majority of the group,
is similarly pissed.  I just don't care.  But I do care when people
who are self-appointed Internet cops try to make people feel like they
have done something wrong when in fact their crime was minimal or
non-existent.


-Robert Scott
 Ypsilanti, Michigan

Re: Faster for() loops?
Quoted text here. Click to load it

As I said before, I can't speak for the group, but as a long-term reader
I can say what I see as a rough summary of opinions expressed here (in
c.a.e., at least).  Of course, I can't summarise un-expressed opinions
of people who don't care one way or the other.

And again, it's not so much the top-posting itself that is impolite.
There are other groups where top-posting is considered the norm, and
receives no objections - just as there are probably groups where html
posting or SMS language is considered normal.  It's the arrogant
disrespect for common conventions, and the "I don't care what others
think, I'll make my own rules" attitude that is impolite.


Quoted text here. Click to load it

The personal insult was a personal post to a single person, making the
analogies valid (IMHO, of course).  But if you prefer, replace the phone
call or the house visit with a town-hall public meeting.  We are still
talking about conversations between real people who dislike being
name-called.

Quoted text here. Click to load it

No one claims that everyone in the group, or the majority in the group,
get annoyed by top-posting.  But (based on this thread, and countless
others before it), the majority of those *who express an opinion*
dislike top-posting.

Quoted text here. Click to load it

Remember, the "crime" in question was not top-posting - it was
deliberate, repeated top-posting after receiving a polite request to
stop it, followed by a personal insult, although it's still minor in the
grand scheme of things.

Re: Faster for() loops?


Quoted text here. Click to load it


Right. If a person is a jerk about something like this, he's likely
going to a jerk down the line about other stuff. HE is the one who
wants help, yet can't bring himself to behave in a vaguely polite
manner.

Why should any of us bother with him? I for one won't, as mentioned he
immediately went into the killfile.




Brian


Re: Faster for() loops?
On Fri, 30 Sep 2005 11:45:15 GMT, no-one@dont-mail-me.com (Robert

Quoted text here. Click to load it

FWIW (very little, I suspect, I'm not sure why I'm bothering)...

I for one don't find top-posting "rude" per se, but I do find failure
to trim quoting "rude."  IME, top-posters are the most egregious
offenders -- if they can't be bothered to put their comments in
context, they surely can't be bothered to trim irrelevent quotes.

I do find top-posts harder to read, and am more likely to skim and
skip them.  That's really the choice every poster has to make.  If the
post is hard to read, fewer people will put the effort into reading
it.  If you don't want people to actually read your post, top-posting
is a good way to discourage them.

I am most reluctant to respond to top-posts, because the flow of the
conversation is all messed up, and it's usually not worth the effort
to reformat.  So if you want the last word, perhaps its better to top
post.

Finally, I don't plonk posters, I plonk threads.  I was hoping for a
little more useful content out of this one, but it's probably in vain.
I've held on longer than I normally do, and I won't be here much
longer.

Regards,

                               -=Dave
--
Change is inevitable, progress is not.

Site Timeline