Performance Discussion

Discussion in 'ASP General' started by Bobbo, Jul 2, 2003.

  1. Bobbo

    Bobbo Guest

    Hi,

    A colleague and I were having a weasely discussion about
    which of the following methods is quicker...


    Method 1:

    var = False
    If <cond> Then var = True



    Method 2:

    If <cond> Then
    var = True
    Else
    var = False
    End If


    The first is more concise, yet the second is clearer.

    Does anyone have anything to contribute to our debate, to
    save us taking it outside?!? ;-)
    Bobbo, Jul 2, 2003
    #1
    1. Advertising

  2. Bobbo

    Bob Barrows Guest

    You're right: "weasely" is a good term. I doubt a user will ever detect the
    difference between these two methods. In a looping situation, I might use
    the first method. In any other situation, it will not matter. Use whichever
    suits your style.

    YMMV,
    Bob Barrows

    Bobbo wrote:
    > Hi,
    >
    > A colleague and I were having a weasely discussion about
    > which of the following methods is quicker...
    >
    >
    > Method 1:
    >
    > var = False
    > If <cond> Then var = True
    >
    >
    >
    > Method 2:
    >
    > If <cond> Then
    > var = True
    > Else
    > var = False
    > End If
    >
    >
    > The first is more concise, yet the second is clearer.
    >
    > Does anyone have anything to contribute to our debate, to
    > save us taking it outside?!? ;-)
    Bob Barrows, Jul 2, 2003
    #2
    1. Advertising

  3. Bobbo

    Ray at Guest

    How about:

    var = <cond>

    :p

    Ray at work

    "Bobbo" <> wrote in message
    news:099c01c3409c$85593e00$...
    > Hi,
    >
    > A colleague and I were having a weasely discussion about
    > which of the following methods is quicker...
    >
    >
    > Method 1:
    >
    > var = False
    > If <cond> Then var = True
    >
    >
    >
    > Method 2:
    >
    > If <cond> Then
    > var = True
    > Else
    > var = False
    > End If
    >
    >
    > The first is more concise, yet the second is clearer.
    >
    > Does anyone have anything to contribute to our debate, to
    > save us taking it outside?!? ;-)
    Ray at, Jul 2, 2003
    #3
  4. Bobbo

    Bobbo Guest

    For those interested, in a 100 million iteration loop,
    Method 1 was the quickest (at approx 90% the time of
    Method 2).

    Incidentally, VB's IIF function was 10 times *slower* than
    either of these two!

    Right, I've finished being weasely now!

    B.
    Bobbo, Jul 2, 2003
    #4
  5. Bobbo

    Ray at Guest

    I don't really think this is what he was looking for though, hence the ":p"
    thing. Like, he was probably just using t/f as an example. My guess is
    that he was wondering between something more like:


    var = "Joe Jones"
    If <cond> var = "Mary Jones"

    vs.

    If <cond> Then
    var = "Mary Jones"
    Else
    var = "Joe Jones"
    End If

    In that case, I'd probably bet a dollar on the top method.

    Ray at work

    "Dave Anderson" <> wrote in message
    news:...
    > "Ray at <%=sLocation%>" wrote:
    > >
    > > How about:
    > >
    > > var = <cond>

    >
    > Amen.
    >
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
    Ray at, Jul 2, 2003
    #5
  6. "Bobbo" <> wrote in message
    news:0abe01c340a8$ee6a8eb0$...
    > For those interested, in a 100 million iteration loop,
    > Method 1 was the quickest (at approx 90% the time of
    > Method 2).
    >
    > Incidentally, VB's IIF function was 10 times *slower* than
    > either of these two!
    >
    > Right, I've finished being weasely now!
    >
    > B.


    Here are my findings:

    Method 1: If
    Method 2: If..Else
    Method 3:Let

    True
    Method 1: 1.371094
    Method 2: 0.9726563
    Method 3: 0.7382813

    False
    Method 1: 0.9101563
    Method 2: 0.921875
    Method 3: 0.7304688

    Mod
    Method 1: 2.003906
    Method 2: 1.792969
    Method 3: 1.191406

    I tested three case. Condition false, condition true and condition =
    iterator mod 2. The mod 2 condition is important since it covers the
    boolean space. In all three cases, Ray's let method was the best
    performer. When the condition was true or mod 2, method 2 (if..else)
    beat out method 1 (if). Only when the condition was false did method 1
    beat out method 2 and then only by a small margin. So if I had to rank
    them it would be method 3 (let), method 2 (if..else), method 1 (if).

    HTH
    -Chris
    Chris Hohmann, Jul 2, 2003
    #6
  7. Bobbo

    Mark Schupp Guest

    Actually the 1st structure would be doing 2 string assignments if the
    condition is true where the 2nd structure always does a single string
    assignment and should be faster overall. That said, I often use the 1st
    structure to reduce the nesting level of complex if statements.

    ---1.a---
    var = "Joe Jones"
    If False Then var = "Mary Jones"
    1,000,000 tries =>3023 ms

    ---2.a---
    If False Then
    var = "Mary Jones"
    Else
    var = "Joe Jones"
    End If
    1,000,000 tries =>3004 ms

    ---1.b---
    var = "Joe Jones"
    If True Then var = "Mary Jones"
    1,000,000 tries =>4547 ms

    ---2.b---
    If True Then
    var = "Mary Jones"
    Else
    var = "Joe Jones"
    End If
    1,000,000 tries =>3145 ms


    --
    Mark Schupp
    --
    Head of Development
    Integrity eLearning
    Online Learning Solutions Provider

    http://www.ielearning.com
    714.637.9480 x17


    "Ray at <%=sLocation%>" <> wrote in message
    news:...
    > I don't really think this is what he was looking for though, hence the

    ":p"
    > thing. Like, he was probably just using t/f as an example. My guess is
    > that he was wondering between something more like:
    >
    >
    > var = "Joe Jones"
    > If <cond> var = "Mary Jones"
    >
    > vs.
    >
    > If <cond> Then
    > var = "Mary Jones"
    > Else
    > var = "Joe Jones"
    > End If
    >
    > In that case, I'd probably bet a dollar on the top method.
    >
    > Ray at work
    >
    > "Dave Anderson" <> wrote in message
    > news:...
    > > "Ray at <%=sLocation%>" wrote:
    > > >
    > > > How about:
    > > >
    > > > var = <cond>

    > >
    > > Amen.
    > >
    > >
    > >
    > > --
    > > Dave Anderson
    > >
    > > Unsolicited commercial email will be read at a cost of $500 per message.

    > Use
    > > of this email address implies consent to these terms. Please do not

    > contact
    > > me directly or ask me to contact you directly for assistance. If your
    > > question is worth asking, it's worth posting.
    > >
    > >

    >
    >
    Mark Schupp, Jul 3, 2003
    #7
  8. Bobbo

    Ray at Guest

    You are correct!

    I ran through each method 10 million times, and got these results:

    Method 1:
    59 seconds

    Method 2:
    42 seconds

    "Mark Schupp" <> wrote in message
    news:...
    > Actually the 1st structure would be doing 2 string assignments if the
    > condition is true where the 2nd structure always does a single string
    > assignment and should be faster overall. That said, I often use the 1st
    > structure to reduce the nesting level of complex if statements.
    >
    > ---1.a---
    > var = "Joe Jones"
    > If False Then var = "Mary Jones"
    > 1,000,000 tries =>3023 ms
    >
    > ---2.a---
    > If False Then
    > var = "Mary Jones"
    > Else
    > var = "Joe Jones"
    > End If
    > 1,000,000 tries =>3004 ms
    >
    > ---1.b---
    > var = "Joe Jones"
    > If True Then var = "Mary Jones"
    > 1,000,000 tries =>4547 ms
    >
    > ---2.b---
    > If True Then
    > var = "Mary Jones"
    > Else
    > var = "Joe Jones"
    > End If
    > 1,000,000 tries =>3145 ms
    >
    >
    > --
    > Mark Schupp
    > --
    > Head of Development
    > Integrity eLearning
    > Online Learning Solutions Provider
    >
    > http://www.ielearning.com
    > 714.637.9480 x17
    >
    >
    > "Ray at <%=sLocation%>" <> wrote in message
    > news:...
    > > I don't really think this is what he was looking for though, hence the

    > ":p"
    > > thing. Like, he was probably just using t/f as an example. My guess is
    > > that he was wondering between something more like:
    > >
    > >
    > > var = "Joe Jones"
    > > If <cond> var = "Mary Jones"
    > >
    > > vs.
    > >
    > > If <cond> Then
    > > var = "Mary Jones"
    > > Else
    > > var = "Joe Jones"
    > > End If
    > >
    > > In that case, I'd probably bet a dollar on the top method.
    > >
    > > Ray at work
    > >
    > > "Dave Anderson" <> wrote in message
    > > news:...
    > > > "Ray at <%=sLocation%>" wrote:
    > > > >
    > > > > How about:
    > > > >
    > > > > var = <cond>
    > > >
    > > > Amen.
    > > >
    > > >
    > > >
    > > > --
    > > > Dave Anderson
    > > >
    > > > Unsolicited commercial email will be read at a cost of $500 per

    message.
    > > Use
    > > > of this email address implies consent to these terms. Please do not

    > > contact
    > > > me directly or ask me to contact you directly for assistance. If your
    > > > question is worth asking, it's worth posting.
    > > >
    > > >

    > >
    > >

    >
    >
    Ray at, Jul 3, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geno

    Discussion

    Geno, Jul 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    514
  2. mohammed rafi

    a discussion about verification

    mohammed rafi, Aug 14, 2004, in forum: VHDL
    Replies:
    12
    Views:
    835
    Andy Freeman
    Aug 21, 2004
  3. ALuPin

    Discussion "Async Reset"

    ALuPin, Oct 25, 2004, in forum: VHDL
    Replies:
    2
    Views:
    643
    Raghavendra
    Oct 27, 2004
  4. jm
    Replies:
    1
    Views:
    498
    alien2_51
    Dec 12, 2003
  5. Software Engineer
    Replies:
    0
    Views:
    309
    Software Engineer
    Jun 10, 2011
Loading...

Share This Page