Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #18745

Re: Which operation is more expensive?(a <= b and a != 0)

From Barry Schwarz <schwarzb@dqel.com>
Newsgroups comp.lang.c
Subject Re: Which operation is more expensive?(a <= b and a != 0)
Date 2012-03-13 22:07 -0700
Organization Aioe.org NNTP Server
Message-ID <4kbvl79eq6k5q3loacbpgicedjfflu5ccq@4ax.com> (permalink)
References <jigsb4$rdc$1@speranza.aioe.org> <2c090628-cf7b-42b0-9266-e9559378e142@t16g2000yqt.googlegroups.com> <67ee38a6-70d0-41f9-a5bd-01ff314e40fe@y10g2000vbn.googlegroups.com>

Show all headers | View raw


On Mon, 27 Feb 2012 18:16:59 -0800 (PST), Peter Nilsson
<airia@acay.com.au> wrote:

>Barry Schwarz <schwar...@yahoo.com> wrote:
>> Ping Cheu <nos...@nospam.com> wrote:
>> > I saw bellow optimization rule.
>> >         for (i = 1; i <= n; i++)
>...
>> >         for (i = n; i != 0; i--)
>...
>> In the general case, tha author is merely displaying is
>> lack of experience and imagination.
>
>I suppose BWK was demonstrating the same lack of experience and
>imagination when he wrote Exercise 2.9 in K&R2, implying...
>
>  for (b = 0; x; x &= x - 1)
>    b++;
>
>...was always faster than...
>
>  for (b = 0; x != 0; x >>= 1)
>    if (x & 01)
>      b++;
>
>These sorts of tricks are still relevant, just considerably
>less significant.

Since BWK started the discussion with the caveat "In a two's
complement system ...", he specifically avoided making a general
assertion.  Furthermore, he only claimed it was useful for writing a
faster bit counting function, not that it had some property of
universal superiority.

It wouldn't surprise me if the trick had other applications also.  It
also wouldn't surprise me if there were other non-obvious tricks which
could be proven to increase efficiency.

But neither of those points has anything to do with my comment that
the author of the original assertion that started this thread was
making global pronouncements without any supporting basis.

-- 
Remove del for email

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Which operation is more expensive?(a <= b and a != 0) Ping Cheu <nospam@nospam.com> - 2012-02-27 21:24 +0000
  Re: Which operation is more expensive?(a <= b and a != 0) James Kuyper <jameskuyper@verizon.net> - 2012-02-27 16:47 -0500
    Re: Which operation is more expensive?(a <= b and a != 0) Michael Angelo Ravera <maravera@prodigy.net> - 2012-03-07 04:23 -0800
  Re: Which operation is more expensive?(a <= b and a != 0) Keith Thompson <kst-u@mib.org> - 2012-02-27 13:54 -0800
    Re: Which operation is more expensive?(a <= b and a != 0) falk@rahul.net (Edward A. Falk) - 2012-02-27 23:47 +0000
  Re: Which operation is more expensive?(a <= b and a != 0) Shao Miller <sha0.miller@gmail.com> - 2012-02-27 16:57 -0500
    Re: Which operation is more expensive?(a <= b and a != 0) Stephen Sprunk <stephen@sprunk.org> - 2012-02-28 13:43 -0600
  Re: Which operation is more expensive?(a <= b and a != 0) Richard Damon <news.x.richarddamon@xoxy.net> - 2012-02-27 16:58 -0500
  Re: Which operation is more expensive?(a <= b and a != 0) Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-27 13:55 -0800
    Re: Which operation is more expensive?(a <= b and a != 0) Kenneth Brody <kenbrody@spamcop.net> - 2012-03-03 15:58 -0500
  Re: Which operation is more expensive?(a <= b and a != 0) Keith Thompson <kst-u@mib.org> - 2012-02-27 14:17 -0800
  Re: Which operation is more expensive?(a <= b and a != 0) Barry Schwarz <schwarz45@yahoo.com> - 2012-02-27 14:52 -0800
    Re: Which operation is more expensive?(a <= b and a != 0) Peter Nilsson <airia@acay.com.au> - 2012-02-27 18:16 -0800
      Re: Which operation is more expensive?(a <= b and a != 0) qarnos <darrencubitt@gmail.com> - 2012-02-29 12:20 -0800
      Re: Which operation is more expensive?(a <= b and a != 0) Barry Schwarz <schwarzb@dqel.com> - 2012-03-13 22:07 -0700
  Re: Which operation is more expensive?(a <= b and a != 0) Kaz Kylheku <kaz@kylheku.com> - 2012-02-28 00:56 +0000
  Re: Which operation is more expensive?(a <= b and a != 0) Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-02-27 19:18 -0700
    Re: Which operation is more expensive?(a <= b and a != 0) China Blue Sea <chine.bleu@yahoo.com> - 2012-02-27 18:30 -0800
  Re: Which operation is more expensive?(a <= b and a != 0) "BartC" <bc@freeuk.com> - 2012-02-28 13:22 +0000
  Re: Which operation is more expensive?(a <= b and a != 0) Stephen Sprunk <stephen@sprunk.org> - 2012-02-28 13:38 -0600
  Re: Which operation is more expensive?(a <= b and a != 0) jgk@panix.com (Joe keane) - 2012-02-28 22:35 +0000
    Re: Which operation is more expensive?(a <= b and a != 0) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-03-03 01:36 +0200
      Re: Which operation is more expensive?(a <= b and a != 0) jgk@panix.com (Joe keane) - 2012-03-05 20:03 +0000
        Re: Which operation is more expensive?(a <= b and a != 0) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-03-12 01:08 +0200
          Re: Which operation is more expensive?(a <= b and a != 0) Harald van Dijk <haraldvdijk@gmail.com> - 2012-03-12 00:05 -0700
            Re: Which operation is more expensive?(a <= b and a != 0) James Kuyper <jameskuyper@verizon.net> - 2012-03-12 08:59 -0400
              Re: Which operation is more expensive?(a <= b and a != 0) gwowen <gwowen@gmail.com> - 2012-03-12 06:24 -0700
                Re: Which operation is more expensive?(a <= b and a != 0) James Kuyper <jameskuyper@verizon.net> - 2012-03-12 10:13 -0400
                Re: Which operation is more expensive?(a <= b and a != 0) Keith Thompson <kst-u@mib.org> - 2012-03-12 10:44 -0700
                Re: Which operation is more expensive?(a <= b and a != 0) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-03-13 17:12 +0200
          Re: Which operation is more expensive?(a <= b and a != 0) Keith Thompson <kst-u@mib.org> - 2012-03-12 11:20 -0700

csiph-web