Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Multiple "If - End If" question

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,29898
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Multiple "If - End If" question
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Multiple "If - End If" question - 1/20/2006 3:10:34 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
I prefer case over multiple Ifs just because I thinik it is easier to read. In general I try to avoid either and solve complex logic constructs through creative data structures. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Post #: 21
 
 RE: Multiple "If - End If" question - 1/20/2006 4:07:39 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
i use it mainly for readability, i didnt know all the stuff that has been presented in this thread. im glad you started this thread to ask 

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to Fredledingue)
 
 
Post #: 22
 
 RE: Multiple "If - End If" question - 1/20/2006 9:20:37 AM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
What I found interesting about this thread is the assertion that If...Then is faster than Select Case.  Now, for the last 3 years, I have been hearing that Select Case is faster, as the expression only has to be evaluated once, whereas in If...Then statements, the expression has to be evaluated for each 'Else' or 'ElseIf'.
So, after this thread made its way to my greedy little eyes, I decided to do some benchmarking.  Whee!

      

Well, I was stunned!  Everything that I had been told was a LIE!  Well, at least about select case vs. If...Then!!


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to kirrilian)
 
 
Post #: 23
 
 RE: Multiple "If - End If" question - 1/20/2006 9:57:17 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
I have some problems with this code, please explain:
quote:


end2 = Timer - start1

Wouldn't you want to subtract the time from start2 rather than start1?

I did a little rewriting and came up with this:

      

with these results:
If...Then takes 0.15625 whereas Select Case takes 0.125 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.125 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.109375 to do the same work.
If...Then takes 0.140625 whereas Select Case takes 0.125 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.109375 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.125 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.109375 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.125 to do the same work.
If...Then takes 0.15625 whereas Select Case takes 0.125 to do the same work.
If...Then takes 0.171875 whereas Select Case takes 0.125 to do the same work.


thoughts?

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 24
 
 RE: Multiple "If - End If" question - 1/20/2006 10:05:37 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Of course each person trusts his/her own benchmarks. Using my benchmark
code from the posting to the "array/function" problem
(http://www.visualbasicscript.com/m_30061/tm.htm)

I added the dictionary entries

    dicMethod.Add "01 tElseIf"       , Array( 10000000, "a"        )
    dicMethod.Add "02 tElseIf"       , Array( 10000000, "z"        )
    dicMethod.Add "01 tSelect"       , Array( 10000000, "a"        )
    dicMethod.Add "02 tSelect"       , Array( 10000000, "z"        )

and the subs


      


      

I got

### Xplore ####################################################################
=== VBSArrayB: VBScript Arrays Bench ==========================================
 ----- 01 tElseIf ----- P: ( 10000000, a )
       Ok.
       00:00:06 for 01 tElseIf
 ----- 02 tElseIf ----- P: ( 10000000, z )
       Ok.
       00:00:20 for 02 tElseIf
 ----- 01 tSelect ----- P: ( 10000000, a )
       Ok.
       00:00:07 for 01 tSelect
 ----- 02 tSelect ----- P: ( 10000000, z )
       Ok.
       00:00:16 for 02 tSelect
=== VBSArrayB: 0 done (00:00:49) ==============================================
### Xplore erfolgreich beendet ################################################


In earnest - I don't doubt your results - I got

### Xplore ####################################################################
=== IfSelB: if/select benchmark ===============================================
If...Then takes 60,00% of the time Select Case takes to do the same work.
If...Then takes 50,00% of the time Select Case takes to do the same work.
If...Then takes 60,00% of the time Select Case takes to do the same work.
If...Then takes 60,00% of the time Select Case takes to do the same work.
If...Then takes 50,00% of the time Select Case takes to do the same work.
If...Then takes 60,00% of the time Select Case takes to do the same work.
If...Then takes 60,00% of the time Select Case takes to do the same work.
If...Then takes 50,00% of the time Select Case takes to do the same work.
If...Then takes 50,00% of the time Select Case takes to do the same work.
If...Then takes 50,00% of the time Select Case takes to do the same work.
=== IfSelB: 0 done (00:00:01) =================================================
### Xplore erfolgreich beendet ################################################

from your code - but I really would like an explanation.

(in reply to kirrilian)
 
 
Post #: 25
 
 RE: Multiple "If - End If" question - 1/20/2006 10:27:14 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Ah - I didn't read kirrilian's contribution before coding - this variable name blunder
could have been one of my own. But a more general caveat: the timer docs state
explicitly:

    Returns the number of seconds that have elapsed since 12:00 AM (midnight).

so you should plan your benchmarks for longer times (and be afraid of timing the
loop overhead instead of the functions you're interested in).

(in reply to ehvbs)
 
 
Post #: 26
 
 RE: Multiple "If - End If" question - 1/20/2006 11:08:12 AM   
  Fredledingue


Posts: 383
Score: 0
Joined: 5/9/2005
From:
Status: offline
This gives me 209% (4.82 sec) for End...If and 100% (2.31 sec) for Select Case...
But if b=1 (first case) then time is 99.2% (1.2 sec) for End...If and 100% (1.209 sec) for Select Case!
Try yourself.





      

_____________________________

Fred

(in reply to ehvbs)
 
 
Post #: 27
 
 RE: Multiple "If - End If" question - 1/21/2006 12:28:52 PM   
  DiGiTAL.SkReAM


Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
quote:

ORIGINAL: kirrilian

I have some problems with this code, please explain:
quote:


end2 = Timer - start1

Wouldn't you want to subtract the time from start2 rather than start1?


Grrrr... Yes.  I had used start1 instead of start2.  My screwup.
I switched the number, and realized that Select Case is in truth faster than IF...Then.  Glad someone was around to point out my error before I started rewriting all of my scripts!  heheheheh


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to kirrilian)
 
 
Post #: 28
 
 RE: Multiple "If - End If" question - 1/23/2006 5:20:16 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
Ehvbs wrote

quote:

       ... However, if only one expression is Null, that expression is
         treated as a zero-length string ("") when concatenated with the other
         expression. ...
      I really don't like "however" in the docs of a programming language.
      Checking the "+" Docs:
         ... If one or both expressions are Null expressions, result is Null..
      Then I knew that I had to use "+" to concatenate strings. I can't risk
      to let concatenations with unexpected Null values pass thru silently.
 


Recently, I had the issue that a WQL query could give a variable a string value or a Null.
I was glad that I could use '&' to show a number of strings resulting from the query, without
loosing the content due to one Null. So a Null does not always mean that an operation went wrong.
Ok, lets say that that are not unexpected Null values.
 

_____________________________

Regular Expression ? I (L+o{1,}v{1,3}e\s)+[iI]t!$

(in reply to ehvbs)
 
 
Post #: 29
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Multiple "If - End If" question Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts