Re: Cost/Benefit with respect to If ... Then.. structure



ScardyBob wrote:
I have a general question related to the structure of a If ... Then ...
statement. More specifically what are the costs/benefits from writing
an If ... Then ... statement as follows:

If i <> 0 Then
'Do Nothing
Else
'Code you want to do something productive
End If

Rather then writing it as:

If i = 0 Then
'Code you want to do something productive
End If

I know this may seem like a stupid question, but I've been writing
certain If ... Then ... statements in the first manner, thinking they
are equivalent and simply a manner of personnel preference. Is there a
downside to this (besides having to write an extra line or two)?


The difference is the first one has an additional
instruction (the Else statement) that will consume a
nanosecond or two of execution time. This cost is modified
by the probablility of i being 0 or not. When i <> 0, there
is no difference, the additional execution time only occurs
when i = 0.

Bottom line, on today's modern computers, the difference is
so small that you will not notice it unless it is in a loop
with a very large number of iterations.

--
Marsh
MVP [MS Access]
.



Relevant Pages

  • Re: How to speed up creation of an ASCII-file?
    ... More than 75% of the execution time of my application is spent writing ... This could be a complete red herring, but to what type of filesystem are you writing? ... My experience with this, uh, "effect" is several years old but I found writing to RAID filesystems tended to be much slower than writing to a regular jbodfilesystem. ... How can I put some pepper in the creation of these ASCII-files? ...
    (comp.lang.fortran)
  • Output files in binary or ASCII?
    ... I am curious what the difference in execution time of a program can be ... when writing output files in ASCII format rather than binary. ... Is there a significant speed advantage I could stand to gain by writing ...
    (comp.lang.fortran)
  • Re: Short-lived Objects - good or bad?
    ... and then writing a second version that performed the same operations but ... preferred mutating existing objects. ... the difference in execution time was on the ... order of hundreds of milliseconds - that is, ...
    (comp.lang.java.programmer)
  • Cost/Benefit with respect to If ... Then.. structure
    ... More specifically what are the costs/benefits from writing ... statements in the first manner, ... downside to this? ...
    (microsoft.public.access.modulesdaovba)
  • Re: Performance problem when using movaps SSE instruction.
    ... the numbers is necessary before reading, therefore writing preceds the ... execution time is not affected by the writing to the address. ... int vector ...
    (alt.lang.asm)