Mystery: static variables & performance

A

Alan Balmer

Try visiting, say, comp.lang.perl.misc. The folks there are quite helpful.

Mark

Are they really good with questions about the C language? Should I
switch?
 
M

Mark McIntyre

You've used selective snipping, and thereby misrepresented the
situation.

Nope. You've misunderstood it.
"As Sidney pointed out, you aimed your use of the term "nazi" directly
at me, and I agree with Sidney that this took it one step too far. Yet,
you've offered no direct apology. The tone of your opening paragraph
signals that you're not in an apologetic mood at all. So, your FWIW is
not worth very much."

So, an apology to Sidney, while laudable, is hardly sufficient.

I wasn't apologising to you, you dolt. I don't give a monkeys if I offended
you. Sidney I care about. Sidney's opinion matters.
Wonderful. It's a free world, so you can simply choose not to
contribute to this thread if you truly believe that.

Or I can start posting "Troll Alert" messages whenever I see you posting.
I'm still havering.
 
M

Mark Shelor

Mark said:
I wasn't apologising to you, you dolt. I don't give a monkeys if I offended
you. Sidney I care about. Sidney's opinion matters.


Please don't strain yourself. I never accused you of apologizing to me.

If hurling epithets helps to lower your blood pressure, then go for it!
It's probably better that you're more concerned with your health than
with your stature.

Or I can start posting "Troll Alert" messages whenever I see you posting.
I'm still havering.


First it was the dreaded killfile. Now it's the deadly troll-alert.
When will my worries cease?

As I've endeavored to tell you repeatedly--with politeness and
respect--if you don't care for my comments on this thread or others,
then just ignore them instead of trying to exercise censorship. If you
continue to make inflammatory remarks, I'll more than likely continue to
respond to them.

Mark
 
M

Mark Shelor

Nils said:
You are correct


Why ... thank you! ;)

both "sides" are trying to force a particular behaviour.

You are trying to get the group to behave in the way you want.

The group is trying to get you to behave in the way that most group
members already does.

I know who I think is beeing unreasonable.


Now now, Nils. I'm not interested in getting the group to behave the
way I want. Perhaps you don't see the distinction, but there's a BIG
difference between *preferring* that certain members of the group behave
a particular way, and attempting to *force* them to behave that way. I
think the latter is not only wrong-headed, but impractical.

If you carefully review the posts in this thread, you'll notice that
certain others are indeed attempting to force me to conform to their
particular view of this newsgroup. This is obvious from their remarks,
which at times range from merely intemperate to overtly aggressive and
hostile. From time-to-time, I have made somewhat barbed remarks, but
only in response to individuals who have overstepped themselves.

Censorship is not allowing somone else to make a statement.
Self-censorship is deciding (for whatever reason) not to make a statement.
Choosing not to listen to someone elses statement has nothing to do with
censorship.


Indeed. You're absolutely correct. If I choose to ignore someone
else's comments, that's not censorship. But if I go to the extent of
making sure that I never even see one of their comments again, that's
self-censorship. I'm not saying there's anything tragically bad about
that. It undoubtedly helps people who get upset at the mere existence
of things.

For example, much of American politics in the last few years has been
quite upsetting to me, and at times I feel like shutting off all news
channels. But, it's not particularly helpful to be left in the dark,
and eventually (let's hope) things will get better. So, I continue to
selectively watch the news, and try to avoid the more inflammatory channels.


1. Explain why you think the questions should be on topic and why that
would be better for the group as a whole.
2. Explain why ignoring offtopic posts is better at preserving topicality
than redirecting those posts.
3. Accept things as they are.

You have as far as I know done neither. You have instead been claiming
that your way is better without explaining why it is better for the
members of this group.


I personally believe that it's best not to try to govern things too
strictly in an unmoderated group. But, that's my belief. To try to
enforce such a belief would be obviously self-contradictory.

And, my *personal* view is that this group would be richer and more
broadly helpful if it oriented itself around the "computer language c"
instead of the "computer standard c". But these matters are ultimately
up to the newsgroup "in toto" to decide; they're not up to selected
groups of individuals to dictate, no matter how loud their voices.

From a practical viewpoint, however, it is far more effective in the
long-run for participants to simply ignore posts that they don't
consider topical. Then, if most or all participants feel the same way,
no responses will be issued to questions that are thereby de-facto
off-topic. This is the way to manifest a true consensus. Off-topic
posters will quickly realize the situation when they receive no
responses to their questions. And, they may even get the motivation at
that point to read the newsgroup FAQ if they can't understand the silence.

In my own case, I received helpful responses to the query on static
variables and performance. And, these responses stand boldly in the
thread, so the "lurkers support me in email" disbelievers will have to
remain silent this time. Were my query truly off-topic, this wouldn't
have happened. Given the length of (and diversity of responses on) this
thread, it's obvious that there's no de-facto consensus on what's
strictly topical. Some people are simply louder and more aggressive
than others.

No not an order. I said I "expect", that is given that you actually care
as much as your posts in this thread seems to indicate. The reason for the
"tone" is that when people complain about something and then fail to make
the obvious steps to change them I get a little impatient with them.


Yes, I get impatient myself, so I know the frustration. Heeding the
advice of Epictetus--to concern yourself only in matters within your
control--is very helpful in this regard. The behavior of others is not
within our control, particularly in an unmoderated group.

Mark
 
M

Mark McIntyre

As I've endeavored to tell you repeatedly--with politeness and
respect--if you don't care for my comments on this thread or others,
then just ignore them instead of trying to exercise censorship.

Good grief, I'm not trying to exercise censorship, I'm trying to point out
to you that you're driving on the wrong side of the road.

When you make topical remarks about C, I've no problem. I'm happy to read
them, you'll get comment on them from time to time if I feel you've
misexplained or erred.

When you make offtopic remarks, or inflammatory remarks, then expect to be
flamed. By the way, I consider childishness inflammatory - eg stuff like
"cue drumroll - the blessed Standard".
If you
continue to make inflammatory remarks, I'll more than likely continue to
respond to them.

*shrug*
 
M

Mark McIntyre

First it was the dreaded killfile. Now it's the deadly troll-alert.
When will my worries cease?

Well, given that I suspect most of the Regulars have already killfiled you,
quite soon, Because soon nobody of any knowledge here will be reading your
posts, spotting mistakes, or answering your queries.

Its your lookout. You want CLC to be useful, abide by the rules. You want
to find it useless, ignore them.
 
M

Mark Shelor

Mark said:
Good grief, I'm not trying to exercise censorship, I'm trying to point out
to you that you're driving on the wrong side of the road.


And, that's all I'm trying to point out to you as well. So we're both
looking after each other's best interests. That's good.

When you make offtopic remarks, or inflammatory remarks, then expect to be
flamed. By the way, I consider childishness inflammatory - eg stuff like
"cue drumroll - the blessed Standard".


Perhaps it's a US/UK thing, like driving on the wrong side of the road.
But "(drum roll please) THE STANDARD" seems a bit less inflammatory
than "dolt" and "nazi".
 
M

Mark Shelor

Mark said:
Well, given that I suspect most of the Regulars have already killfiled you,
quite soon, Because soon nobody of any knowledge here will be reading your
posts, spotting mistakes, or answering your queries.

Its your lookout. You want CLC to be useful, abide by the rules. You want
to find it useless, ignore them.


To borrow one of your favorite expressions,

*shrug*
 
C

CBFalconer

Mark said:
.... snip ...

From a practical viewpoint, however, it is far more effective in the
long-run for participants to simply ignore posts that they don't
consider topical. Then, if most or all participants feel the same way,
no responses will be issued to questions that are thereby de-facto
off-topic. This is the way to manifest a true consensus. Off-topic
posters will quickly realize the situation when they receive no
responses to their questions. And, they may even get the motivation at
that point to read the newsgroup FAQ if they can't understand the silence.

You are selfishly posting off-topic material that has to be
propagated all over the world. Many users pay for every second of
their connect time, and do not want to be forced to transfer your
self aggrandizements. Those users SHOULD be protected by the fact
that they are participating in a newsgroup with a specific area of
topicality.

You are a childish boor to insist on interrupting this group with
your wants. We are not amused.
 
M

Mark Shelor

CBFalconer said:
You are selfishly posting off-topic material that has to be
propagated all over the world. Many users pay for every second of
their connect time, and do not want to be forced to transfer your
self aggrandizements. Those users SHOULD be protected by the fact
that they are participating in a newsgroup with a specific area of
topicality.


Then do your part to help those users by ceasing to post against this
thread. This debate and thread could have been concluded ages ago if
you and others would desist from trying to practice censorship.

You are a childish boor to insist on interrupting this group with
your wants. We are not amused.


You will benefit greatly by first examining your own motives before
hurling such pointed remarks. It would appear that you are the one with
the "wants" in this case.

Look, the game is very simple. If you and others can manage to refrain
from issuing pointed and insulting remarks against this thread, then the
debate will come to a close immediately. However, if you insist on
continuing with this practice, then I'll more than likely respond. It's
that simple.

So, if your true desire is to protect the users (as you allude to in
your opening paragraph), then you have the full means to achieve that.
 
R

R. Rajesh Jeba Anbiah

Mark Shelor said:
And, my *personal* view is that this group would be richer and more
broadly helpful if it oriented itself around the "computer language c"
instead of the "computer standard c". But these matters are ultimately
up to the newsgroup "in toto" to decide; they're not up to selected
groups of individuals to dictate, no matter how loud their voices.

From a practical viewpoint, however, it is far more effective in the
long-run for participants to simply ignore posts that they don't
consider topical. Then, if most or all participants feel the same way,
no responses will be issued to questions that are thereby de-facto
off-topic. This is the way to manifest a true consensus. Off-topic
posters will quickly realize the situation when they receive no
responses to their questions. And, they may even get the motivation at
that point to read the newsgroup FAQ if they can't understand the silence.

In my own case, I received helpful responses to the query on static
variables and performance. And, these responses stand boldly in the
thread, so the "lurkers support me in email" disbelievers will have to
remain silent this time. Were my query truly off-topic, this wouldn't
have happened. Given the length of (and diversity of responses on) this
thread, it's obvious that there's no de-facto consensus on what's
strictly topical. Some people are simply louder and more aggressive
than others.

I'm the idiot who read c.l.c almost frequently for about 4-years.
If I recall correct, many of your comments are sometimes implied by
many people and most of them are gone/plonked/few of them joined. The
interesting thing I have found here is many regulars are respecting
your views or at least listening to your views---which hardly happend
before.

Interestingly, in this thread I've found some good views about the
topicality of c.l.c. For a very longtime, I was thinking myself: K&R
says C is used to write OS/compilers/etc, but many people here why
flame if such questions came here. I was also thinking myself: is ISO
C is a toy language; sometimes ago someone posted a script for itoa()
claiming that it's a "pure ISO C" code; I used to wonder if there is
any compilers/OS written in ISO C; also I would think, this standard
is for the old people who don't like to dig more. And,... of course
yet I haven't got any valid answers.

With lots & lots of wishes.
 
C

CBFalconer

Mark said:
.... snip ...

So, if your true desire is to protect the users (as you allude to in
your opening paragraph), then you have the full means to achieve that.

PLONK Your parents methods of rearing their offspring are suspect.
 
N

nrk

R. Rajesh Jeba Anbiah said:
I'm the idiot who read c.l.c almost frequently for about 4-years.
If I recall correct, many of your comments are sometimes implied by
many people and most of them are gone/plonked/few of them joined. The
interesting thing I have found here is many regulars are respecting
your views or at least listening to your views---which hardly happend
before.

Rajesh, it is unfortunate that inspite of spending around 4 years in
CLC, you haven't realized why the regulars are sticklers for topicality and
to questions related to the ANSIC C Standard. It is not because C is a toy
language. It is not because all (or even most) regulars here are old
people who don't want to dig any more. It simply has to do with the fact
that C is a very versatile and pervasive language. If one were to start
answering any and all questions merely on the basis that it involved C in
some way, the group will become well near useless. As they say, you can
either be a rather poor jack of all trades or be a good master of one.
This group is a good master at answering questions related to the C
language as it is described in the ANSI/ISO standards. By being so picky
about topicality, CLC actually does a favor to off-topic posters. By
forcing them to go to a domain that's richer with experts in their specific
issues it helps them get better quality help than they would get here.
Interestingly, in this thread I've found some good views about the
topicality of c.l.c. For a very longtime, I was thinking myself: K&R
says C is used to write OS/compilers/etc, but many people here why
flame if such questions came here. I was also thinking myself: is ISO
C is a toy language; sometimes ago someone posted a script for itoa()
claiming that it's a "pure ISO C" code; I used to wonder if there is
any compilers/OS written in ISO C; also I would think, this standard
is for the old people who don't like to dig more. And,... of course
yet I haven't got any valid answers.

The answers are right in front of your eyes. Don't wonder why you're not
able to see them as long as you have your eyes shut.

FWIW, Mark's original question was a marginal case IMO. For instance,
declaring his variable static inside a function has the effect that the
array is initialized exactly once. Making it non-static would change this.
Also, he could remove the static and try getting the same effect by passing
in the array in question as a parameter to the function. This way he gets
to maintain state across calls. He can even keep the same call interface
to the end-user by building a wrapper function that calls his inner
function in question. He could also try hinting to the compiler that
certain variables inside the function will be accessed very frequently by
making their storage class "register" (IMHO, most modern compilers
completely ignore this and do a better job of deciding how to allocate
registers).

Barring this, there might be issues as to how his compiler is compiling the
specific code in question. Those questions are best answered by experts
who know how his particular platform and implementation works.

There may also be algorithmic improvements that might benefit him more than
any of this kind of micro-optimizations. Again, that's best answered by
experts who reside elsewhere like comp.programming (or even cryptography
groups).

Mark simply refuses to accept that the generic *all*-platform-encompassing
answers to his question (barring algorithmic improvements) are borderline
useless and that he should perhaps restrict the scope to a handful of
architectures that dominate in today's world and optimize his
implementation for them. Once he does that, he can then ask experts in
those relevant architectures as to what he can do to optimize his code.

-nrk.

PS: Your book, section 4.2: The WAR style example of strcmp is atrocious
IMO. If you must insist on a single return, here's a clearer version of
strcmp:

int strcmp(const char *s1, const char *s2) {
while ( *s1 == *s2 && *s1 )
++s1, ++s2;

return *s1 - *s2;
}
 
M

Mark Shelor

CBFalconer said:
PLONK Your parents methods of rearing their offspring are suspect.


With respect, CBFalconer, resorting to ad-hominem attacks does not
strengthen your position.
 
M

Mark Shelor

nrk said:
FWIW, Mark's original question was a marginal case IMO. For instance,
declaring his variable static inside a function has the effect that the
array is initialized exactly once.


Bravo, nrk! And I DO mean that sincerely. You've used your knowledge
of the C programming language to analyze a situation that's not specific
to any one compiler implementation. And, below, you've suggested ways
to ameliorate the issues mentioned in my original post.

Making it non-static would change this.
Also, he could remove the static and try getting the same effect by passing
in the array in question as a parameter to the function. This way he gets
to maintain state across calls.


Now, on to the details. First bear in mind that there's no necessity
for the array (hereafter referred to as "the message schedule") to have
the storage class "static". The complete contents of the array are
built from scratch each time the function is executed, so the
prior-initialization property of static variables is not relevant in
this case. Furthermore, there's no need to maintain the values of the
message schedule across repeated function calls. In short, the array
can be made into an automatic variable with absolutely no change in the
observed behavior of the program.

But, making this variable automatic has the effect of dramatically
decreasing the function's performance on some platforms, while
significantly increasing it on others. So, the ideal solution would be
to find a consistent way to represent the message schedule such that the
function's performance is at least near-optimal on all platforms. The
goal here is to devise a simple, clean, portable solution that works
consistently, thereby avoiding the maintenance problems associated with
creating a series of #ifdef's that sense each underlying platform and
tweak the message schedule accordingly.

He could also try hinting to the compiler that
certain variables inside the function will be accessed very frequently by
making their storage class "register" (IMHO, most modern compilers
completely ignore this and do a better job of deciding how to allocate
registers).


Yes, your IMHO is correct, at least in this case. The compiler does a
much better job of optimizing compared to a manual use of the register
storage class.

Mark simply refuses to accept that the generic *all*-platform-encompassing
answers to his question (barring algorithmic improvements) are borderline
useless and that he should perhaps restrict the scope to a handful of
architectures that dominate in today's world and optimize his
implementation for them.


You are correct that I do refuse to accept your conjecture, but I also
respect your and other's right to regard this conjecture as fact. Your
interests center primarily on the formal properties of C programs as
they relate to the standard. I regard this as highly important as well,
but in the final analysis have to place primary emphasis on de-facto
portability, clean design, and high performance.

Once he does that, he can then ask experts in
those relevant architectures as to what he can do to optimize his code.


Having a fairly high comfort level with processor architectures and
assembly language programming, I'm not too concerned about how to
optimize performance for specific targets. What I am concerned about,
however, is proceeding to this step before everything possible has been
done to make the clean, portable, C-only version as efficient as possible.

No further algorithmic improvements are obvious at this point. In fact,
my C-only version has already attained the theoretical maximum SHA-1
throughput of 1.7 cycles per bit when built with the Intel compiler on
Pentium platforms. My guess is that only the most deft uses of the
assembler will be successful in squeezing out additional cycles, and any
real advantage of doing so may turn out to be marginal and inconsistent.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top