Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c.moderated > #389
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c.moderated |
| Subject | Re: which one is faster? |
| Date | 2012-04-30 21:57 -0500 |
| Organization | None to speak of |
| Message-ID | <clcm-20120430-0003@plethora.net> (permalink) |
| References | <clcm-20120404-0002@plethora.net> <clcm-20120423-0002@plethora.net> |
Thomas Richter <thor@math.tu-berlin.de> writes:
> On 05.04.2012 01:05, echo ma wrote:
>> on a 32bit system.
>>
>> #pragma pack(4)
>> struct TestStruct
>> {
>> unsigned short a;
>> unsigned short b;
>> unsigned int c;
>> };
>> #pragma pack()
>> struct TestStruct t;
>> t.a = 0; //step 1
>> t.b = 1; //step 2
>> t.c = 2; //step 3
>>
>> Questing is : Are these 3 steps having the same perfomance time?
>
> Sorry, I don't understand. To have something "the same", you need to
> compare two different things. So which two "are the same" or "not the
> same"? I see only one piece of code, and this is not even portable.
> (#pragma pack() is not ANSI-C).
I think echo ma is asking about the relative performance of the three
statements "t.a = 0;", "t.b = 1;", and "t.c = 2;".
I suppose if, for example, the assignment to t.a turned out to be
significantly faster than the assignment to t.b, then it might make
sense to rearrange the struct definition so the most frequently accessed
members are first.
In practice, such rearrangement is unlikely to be helpful.
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to comp.lang.c.moderated | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
which one is faster? echo ma <fatmck@gmail.com> - 2012-04-04 18:05 -0500
Re: which one is faster? James Kuyper <jameskuyper@verizon.net> - 2012-04-23 08:31 -0500
Re: which one is faster? "Joel C. Salomon" <joelcsalomon@gmail.com> - 2012-04-23 08:33 -0500
Re: which one is faster? David Brown <david@westcontrol.removethisbit.com> - 2012-04-23 08:33 -0500
Re: which one is faster? Thomas Richter <thor@math.tu-berlin.de> - 2012-04-23 08:31 -0500
Re: which one is faster? Keith Thompson <kst-u@mib.org> - 2012-04-30 21:57 -0500
Re: which one is faster? Barry Schwarz <schwarzb@dqel.com> - 2012-04-23 08:32 -0500
Re: which one is faster? Keith Thompson <kst-u@mib.org> - 2012-04-23 08:32 -0500
Re: which one is faster? George Neuner <gneuner2@comcast.net> - 2012-04-30 21:58 -0500
csiph-web