Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 what is faster, case or elseif
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 16 April 2001 :  12:24:04  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
im writing a function that is going to go thru about 150 elseif statements and started thinking maybe case would be faster. which one is faster or are they both the exact same?

Brad

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 16 April 2001 :  12:33:58  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
I believe cases are faster, but I could be wrong.

Dave Maxwell
--------------
Proud to be a "World Class" Knucklehead
Go to Top of Page

PJamieson
Starting Member

United Kingdom
11 Posts

Posted - 16 April 2001 :  15:39:07  Show Profile  Visit PJamieson's Homepage
Cases are definately faster. If you are using ElseIf statements the code normally has to check every single item and do a comparison. Case's set up the comparison value at the start.

Also, cases are much easier to read, and neater.

Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 16 April 2001 :  20:41:47  Show Profile
There should be a better way than 150 or so elseif's.

Elseif gives you the ability to test different logical conditions in the same construct, case doesn't.


======
Doug G
======
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 16 April 2001 :  22:47:21  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
well here is a sample.....


Function ReturnMemberConfigData(sID)
Select case cint(sID)
case 1
ReturnMemberConfigData = "Rather Not Say"
case 2
ReturnMemberConfigData = "Other"
case 3
ReturnMemberConfigData = "African American"
case 4
ReturnMemberConfigData = "Asian"
case 5
ReturnMemberConfigData = "Caucasian"


so it really doesnt need to do anything else

Brad
Go to Top of Page

big9erfan
Average Member

540 Posts

Posted - 17 April 2001 :  00:06:41  Show Profile
in small tests, ifelse and cases are near identical, but in LARGE selections, yours will work for this example, having to make a comaprison 149 times is much more time consuming.

A case does not have to compare at each elseif statement, it simply jumps to its given line.

Writing for small processors and such, you'd much prefer to have a case than else ifs. For the systems today, it really doesn't matter as their speed and RAM is so much the simple calculations for comparisons doesn't make much of a dent.



http://www.ugfl.net/forums
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.35 seconds. Powered By: Snitz Forums 2000 Version 3.4.07