Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Mon, 06 Jun 2011 07:21:34 -0500 |
| Message-ID | <4DECC653.2C1C@mindspring.com> (permalink) |
| Date | Mon, 06 Jun 2011 08:21:39 -0400 |
| From | pete <pfiland@mindspring.com> |
| Reply-To | pfiland@mindspring.com |
| Organization | PF |
| X-Mailer | Mozilla 3.04Gold (WinNT; I) |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.c |
| Subject | Re: efficient or clever way |
| References | <70c4add5-a342-40b8-b037-079b1bedc153@x3g2000yqj.googlegroups.com> |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 42 |
| X-Usenet-Provider | http://www.giganews.com |
| NNTP-Posting-Host | 4.154.218.17 |
| X-Trace | sv3-7CBubkQG4YncvrsBILa+GYKOnG7YrT412RM5lJ0NyZLusnNJR++GgBL/qXxbBGipSgTKF4p4yChgJHs!//xexVohVempzqbyVNRpO4UhbidN06RgeCNPdzyHg37SswoDsqUQBDbSlo7+E4959H+oeTw+7EGC!PzXfExx7aQ== |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 2228 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c:5557 |
Show key headers only | View raw
dr.oktopus wrote:
>
> Hello,
> walking an array is a common construct in programming.
> In C language, I see two common practises.
>
> 1:
>
> for (p = array, pend = array + size ; p < pend ; ++p)
> /* do something */
>
> 2:
>
> count = size;
> p = array;
> while (count--) {
> /* do something here */
> ++p;
> }
>
> In complex contests, keeping a count variable could
> be more readable (IMO) than having a variable acting
> as a sentinel for the array bound (I'm speking of pieces
> of codes where array navigation is not from the start
> to the end, or inside Duff's devices, for example).
> My question is: is this code really inefficient than
> first approach (since it has to dec a variable every
> cycle, more than test it) or current cpus could handle a sort
> of decrement and test instr that do it all at the same time?
> Thanks,
> wily
It all depends on the cpu.
Comparing two variables against each other
may or may not be slower
than a decrement plus a comparison against constant zero.
A decrement plus a comparison against constant zero,
is a single instruction in Microchip assembly.
--
pete
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
efficient or clever way "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-06-06 01:29 -0700
Re: efficient or clever way China Blue Angels <chine.bleu@yahoo.com> - 2011-06-06 02:12 -0700
Re: efficient or clever way Chris H <chris@phaedsys.org> - 2011-06-06 12:50 +0100
Re: efficient or clever way "Kleuskes & Moos" <kleuske@xs4all.nl> - 2011-06-06 11:38 -0700
Re: efficient or clever way Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2011-06-08 13:48 -0700
Re: efficient or clever way China Blue Angels <chine.bleu@yahoo.com> - 2011-06-08 16:16 -0700
Re: efficient or clever way "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-06-12 01:10 -0700
Re: efficient or clever way pete <pfiland@mindspring.com> - 2011-06-06 08:21 -0400
Re: efficient or clever way Voice Of Truth <oops@uhm.wow> - 2011-06-06 20:48 +0200
Re: efficient or clever way Keith Thompson <kst-u@mib.org> - 2011-06-06 11:55 -0700
Re: efficient or clever way Voice Of Truth <oops@uhm.wow> - 2011-06-06 20:58 +0200
Re: efficient or clever way pete <pfiland@mindspring.com> - 2011-06-06 19:10 -0400
Re: efficient or clever way Voice Of Truth <oops@uhm.wow> - 2011-06-07 05:54 +0200
Re: efficient or clever way cri@tiac.net (Richard Harter) - 2011-06-06 15:13 +0000
Re: efficient or clever way Keith Thompson <kst-u@mib.org> - 2011-06-06 09:35 -0700
Re: efficient or clever way Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-06-08 20:34 +0000
csiph-web