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


Groups > comp.lang.c++ > #14829

Re: use of pointers

From Maarten <maarten.sneep@knmi.nl>
Newsgroups comp.lang.c++
Subject Re: use of pointers
Date 2012-03-08 04:55 -0800
Organization http://groups.google.com
Message-ID <25296625.140.1331211325127.JavaMail.geo-discussion-forums@ynee13> (permalink)
References (1 earlier) <purdl7lm3o4ika8c6qv5tksii86uj2meco@4ax.com> <slrnjlehf7.1ls.grahn+nntp@frailea.sa.invalid> <jj7peu$g3o$1@dont-email.me> <12360032.6313.1331129642322.JavaMail.geo-discussion-forums@vbgu10> <jj80vp$ogr$1@speranza.aioe.org>

Show all headers | View raw


On Wednesday, March 7, 2012 5:05:15 PM UTC+1, Rui Maciel wrote:
> Maarten wrote:
> 
> > As Donald Knuth once put it: "There is no doubt that the grail
> > of efficiency leads to abuse. Programmers waste enormous amounts
> > of time thinking about, or worrying about, the speed of noncritical
> > parts of their programs, and these attempts at efficiency actually
> > have a strong negative impact when debugging and maintenance are
> > considered. We should forget about small efficiencies, say about
> > 97% of the time: premature optimization is the root of all evil."
> > 
> > Only start optimizing once you have tested your code, and are
> > satisfied that it is correct. And only start to optimize when
> > you have seen that there is a performance issue, and have
> > pinpointed the issue with a profiler.
> > 
> > Yes, Donald Knuth leaves you 3% where it does matter. But he
> > also states that you should only worry about that after you
> > have identified that code.
> > 
> > Article can be found from
> > http://en.wikipedia.org/wiki/Program_optimization
> 
> Knuth's quote tends to be abused a bit.  

Which is why I looked it up, and used a slightly longer quotation. The 
rest of the article is rather interesting.

> Some individuals employ it to, 
> under Knuth's authority, imply that any attention to efficiency, however 
> remote it might be, is also evil, and therefore no attention whatsoever 
> should be ever paid to it.  This may pose a serious problem in applications 
> which do need to run efficiently, as it isn't possible to fix performance 
> problems caused by fundamental design decisions by postponing any attention 
> to the application's efficiency to a testing stage.

Do things in the right order:

* Use an appropriate algorithm. This is where the greatest improvements 
  can be made. This is at the design-stage, not at the programming stage.
  No optimization can dig you out of the hole created by picking the wrong 
  algorithm. 
  
  But on the other hand, spend your time wisely. Initialization is run only 
  once, a loop multiple times. While you may be able to make initialization 
  faster by 90%, on the overall run time the effect may be negligible. 
  Improve the code within a loop by 10%, and you might gain a lot. 

* Get something that is producing the correct results. Make sure the code 
  is readable at this stage. Low-hanging fruit can be harvested, say by 
  removing calculations from a loop that produce constant results. 
  Do not worry about the relative efficiency of 'a != 0' vs 'a > 0'.

* Run the code, and see if performance is an issue. If not: you're done, 
  and you have readable code. If more performance is needed, start your profiler
  and start optimizing from there.

I believe that Knuth was talking about discussion as to whether 'a != 0' 
or 'a > 0' is faster. On that I agree with him. Somehow I think he would 
agree with me on picking the right algorithm, and spending your time there.

Maarten

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


Thread

use of pointers ahso <ahso47@yahoo.com> - 2012-03-06 02:54 -0800
  Re: use of pointers Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-03-06 12:22 +0100
    Re: use of pointers nick_keighley_nospam@hotmail.com - 2012-03-07 00:32 -0800
      Re: use of pointers Juha Nieminen <nospam@thanks.invalid> - 2012-03-07 13:47 +0000
        Re: use of pointers nick_keighley_nospam@hotmail.com - 2012-03-07 07:06 -0800
          Re: use of pointers Juha Nieminen <nospam@thanks.invalid> - 2012-03-07 16:04 +0000
  Re: use of pointers Juha Nieminen <nospam@thanks.invalid> - 2012-03-06 12:29 +0000
    Re: use of pointers Victor Bazarov <v.bazarov@comcast.invalid> - 2012-03-06 08:04 -0500
      Re: use of pointers glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-03-06 14:05 +0000
        Re: use of pointers Victor Bazarov <v.bazarov@comcast.invalid> - 2012-03-06 11:25 -0500
          Re: use of pointers glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-03-06 20:56 +0000
      Re: use of pointers SG <s.gesemann@gmail.com> - 2012-03-06 06:27 -0800
        Re: use of pointers BGB <cr88192@hotmail.com> - 2012-03-06 13:05 -0700
        Re: use of pointers woodbrian77@gmail.com - 2012-03-07 05:38 -0800
      Re: use of pointers Rui Maciel <rui.maciel@gmail.com> - 2012-03-07 15:48 +0000
        Re: use of pointers BGB <cr88192@hotmail.com> - 2012-03-07 18:38 -0700
          Re: use of pointers Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-03-10 21:10 -0500
            Re: use of pointers Jeff Flinn <TriumphSprint2000@hotmail.com> - 2012-03-12 08:26 -0400
              Re: use of pointers Jeff Flinn <TriumphSprint2000@hotmail.com> - 2012-03-12 12:28 -0400
      Re: use of pointers Nobody <nobody@nowhere.com> - 2012-03-09 21:28 +0000
  Re: use of pointers Geoff <geoff@invalid.invalid> - 2012-03-06 21:31 -0800
    Re: use of pointers Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-07 11:26 +0000
      Re: use of pointers yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-03-07 13:56 +0000
        Re: use of pointers Maarten <maarten.sneep@knmi.nl> - 2012-03-07 06:14 -0800
          Re: use of pointers Rui Maciel <rui.maciel@gmail.com> - 2012-03-07 16:05 +0000
            Re: use of pointers yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-03-08 10:08 +0000
              Re: use of pointers Rui Maciel <rui.maciel@gmail.com> - 2012-03-08 21:17 +0000
            Re: use of pointers Maarten <maarten.sneep@knmi.nl> - 2012-03-08 04:55 -0800
          Re: use of pointers Nobody <nobody@nowhere.com> - 2012-03-09 21:45 +0000
        Re: use of pointers Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-07 20:08 +0000
      Re: use of pointers Nobody <nobody@nowhere.com> - 2012-03-09 21:50 +0000
        Re: use of pointers Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-09 22:37 +0000
  Re: use of pointers Rui Maciel <rui.maciel@gmail.com> - 2012-03-07 15:37 +0000

csiph-web