PC Review


Reply
Thread Tools Rate Thread

Comparison performance - String.compare vs Select Case

 
 
=?Utf-8?B?UkpC?=
Guest
Posts: n/a
 
      12th Nov 2004

Can anybody tell me what is the quickest way )most efficient) method of
performing comparisons in vb.net?

I'm making modifications to an asp.Net / vb.net application developed by
someone else. The code base is loaded with nested if statements all doing
string comparisons. The research that I've done so far indicates that
string.compareordinal is more efficient than string.compare but I haven't
been able to locate anything regarding the efficiency of select case vs
either of these compare methods. Essentially I'm looking for a best practice
for string comparisons.

You thoughts are appreciated. Thank you!!
 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      12th Nov 2004
In this case I would be more worried about the readability of the program
then how it is comparing strings. A case statement is much clearer then
nested if statements - so it wins right there.

"RJB" <(E-Mail Removed)> wrote in message
news:BD240FF7-A701-4E5B-9796-(E-Mail Removed)...
>
> Can anybody tell me what is the quickest way )most efficient) method of
> performing comparisons in vb.net?
>
> I'm making modifications to an asp.Net / vb.net application developed by
> someone else. The code base is loaded with nested if statements all doing
> string comparisons. The research that I've done so far indicates that
> string.compareordinal is more efficient than string.compare but I haven't
> been able to locate anything regarding the efficiency of select case vs
> either of these compare methods. Essentially I'm looking for a best

practice
> for string comparisons.
>
> You thoughts are appreciated. Thank you!!



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      12th Nov 2004
RJB,
In addition to Marina's comments.

I too prefer the Select Case over nested Ifs. However, if I need to use an
If, and I am checking a series of related conditions I would use If/ElseIf
instead of nesting the Ifs if at all possible

Dim firstShift As TimeRange
Dim secondShift As TimeRange
Dim thirdShift As TimeRange

Dim clockIn as DateTime

If firstShift.Contains(clockIn) then
' Do something exciting for the first shift
ElseIf secondShift.Contains(clockIn) Then
' Do something exciting for the second shift
ElseIf thirdShift.Contains(clockIn) Then
' Do something exciting for the third shift
Else
' should "never" happen :-)
Throw New ArgumentException("clockIn", clockIn, "Clock is not in any
shifts")
End If

Search this newsgroup for the implementation of TimeRange & why one might
use it.

Hope this helps
Jay

"RJB" <(E-Mail Removed)> wrote in message
news:BD240FF7-A701-4E5B-9796-(E-Mail Removed)...
>
> Can anybody tell me what is the quickest way )most efficient) method of
> performing comparisons in vb.net?
>
> I'm making modifications to an asp.Net / vb.net application developed by
> someone else. The code base is loaded with nested if statements all doing
> string comparisons. The research that I've done so far indicates that
> string.compareordinal is more efficient than string.compare but I haven't
> been able to locate anything regarding the efficiency of select case vs
> either of these compare methods. Essentially I'm looking for a best
> practice
> for string comparisons.
>
> You thoughts are appreciated. Thank you!!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 comparison operators in select case at same level without loss in precision rd Microsoft Excel Programming 1 27th Jul 2007 03:20 PM
Case Insensitive string comparison anonieko@hotmail.com Microsoft C# .NET 6 7th Mar 2007 01:50 PM
Case Insensitive String Comparison? jpuopolo Microsoft C# .NET 7 2nd Feb 2007 09:31 PM
Using SELECT...CASE with comparison operators? Toby Erkson Microsoft Excel Programming 7 14th Jul 2004 09:52 PM
how to case select with case-insensitive string ? Tee Microsoft VB .NET 3 23rd Jun 2004 08:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 AM.