Re: efficiency question - nested function cals

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 02/22/04


Date: Sun, 22 Feb 2004 07:46:01 -0000

Marc Pelletier <no.email@please.com> wrote:
> You are right. On 10,000 iterations the execution time is virtually the
> same.
>
> But I disagree with your other assertion, that I shouldn't worry about
> those issues until I find a bottleneck. I am just learning csharp and this
> is surely the time to establish good practices in this language. Good
> coding style, once established, can carry you far. For example the
> execution time in this case is the same, but the unnested version is much
> easier to debug.

So write that more readable code, as I suggested. If one version is
"much easier to debug", use that version until you find some *really
good* reason not to. It would be silly (IMO) to write less readable
code *everywhere* just because there's a very small chance that the
bottleneck in your code is due to one micro-optimisation. It's far more
likely to end up being either something you can't easily control
(bandwidth, another server, etc), an algorithm, or some combination of
the two (one particular way of doing something which eats bandwidth
when there's an alternative available). I can't remember the last time
a micro-optimisation like this was a problem.

(There's a big difference between this and the similar-looking decision
to use a StringBuilder when building up long strings. That's not a
micro-optimisation of syntax which you can reasonably hope the JIT can
compile away; it's a fundamental problem of creating too many objects.
Even that decision is only relevant when you know the number of strings
to append could end up being reasonably large (or more).)

It's important to get *architecture* right early on - that can make a
*huge* difference to performance, and is very hard to fix later on, but
not actual code.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Ada Shootout program for K-Nucleotide (patches)
    ... execution time. ... and this particular hot spot had been cooled down twice: ... constrained strings of suitable fixed length ... function and a cute string equality function. ...
    (comp.lang.ada)
  • Re: Ada Shootout program for K-Nucleotide (patches)
    ... Ludovic Brenta wrote: ... execution time. ... constrained strings of suitable fixed length ... Operator subprograms seem to confuse the profiling programs, ...
    (comp.lang.ada)
  • Re: Faster datastructure for lookups wanted
    ... My code spends most of its execution time doing lookups from ... The keys are strings and the values ... I do not care how long the construction of the datastructure takes, ... Maybe it is worth trying symbols instead of strings? ...
    (comp.lang.ruby)
  • Re: Fast way to determine if a string contains a member of a list of strings
    ... Really disappointing timings for the state machine method. ... Execution time: 0.055008 seconds. ... I can terminate the search as soon as ONE of the strings is ... efficiently without using a state graph. ...
    (microsoft.public.dotnet.languages.csharp)