ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Performance Difference - LCase vs UCase? (https://www.excelbanter.com/excel-programming/372638-performance-difference-lcase-vs-ucase.html)

MDW

Performance Difference - LCase vs UCase?
 
Hello,

I'm going to be comparing a bunch of string variables in a case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1) =
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant to
me if I compare the strings in upper case or lower. Is it any more "work" for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!

Jim Cone

Performance Difference - LCase vs UCase?
 
If I were doing it I would use the "Like" operator...
If string1 Like string2 Then
This requires the "Option Compare Text" statement at the top of the module.

I doubt if there is any difference in the time required for Ucase vs. Lcase.
If time is an issue, then run each code version and time it..
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"MDW"
wrote in message
Hello,
I'm going to be comparing a bunch of string variables in a case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1) =
LCase(string2) Then..."
However, I'm going to be doing this thousands of times. It's irrelevant to
me if I compare the strings in upper case or lower. Is it any more "work" for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?
Thanks.
--
Hmm...they have the Internet on COMPUTERS now!

RB Smissaert

Performance Difference - LCase vs UCase?
 
I tested this once.
Like is about 30 - 50% faster than using UCase or LCase.
No differenece between UCase and LCase.

RBS

"Jim Cone" wrote in message
...
If I were doing it I would use the "Like" operator...
If string1 Like string2 Then
This requires the "Option Compare Text" statement at the top of the
module.

I doubt if there is any difference in the time required for Ucase vs.
Lcase.
If time is an issue, then run each code version and time it..
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"MDW"
wrote in message
Hello,
I'm going to be comparing a bunch of string variables in a
case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1)
=
LCase(string2) Then..."
However, I'm going to be doing this thousands of times. It's irrelevant to
me if I compare the strings in upper case or lower. Is it any more "work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?
Thanks.
--
Hmm...they have the Internet on COMPUTERS now!



NickHK

Performance Difference - LCase vs UCase?
 
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a

case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1)

=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant to
me if I compare the strings in upper case or lower. Is it any more "work"

for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!




Gary Keramidas

Performance Difference - LCase vs UCase?
 
jim i have a question on this and the option compare text

if i run the following code with option compare text under option explicit, i
get "the same"
if i remove option compare text, i get "different"

why the difference?

Sub test()
str1 = "Gary"
str2 = "gary"

If str1 Like str2 Then
MsgBox "the same"
Else
MsgBox "different"
End If
End Sub


--


Gary


"Jim Cone" wrote in message
...
If I were doing it I would use the "Like" operator...
If string1 Like string2 Then
This requires the "Option Compare Text" statement at the top of the module.

I doubt if there is any difference in the time required for Ucase vs. Lcase.
If time is an issue, then run each code version and time it..
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"MDW"
wrote in message
Hello,
I'm going to be comparing a bunch of string variables in a case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1) =
LCase(string2) Then..."
However, I'm going to be doing this thousands of times. It's irrelevant to
me if I compare the strings in upper case or lower. Is it any more "work" for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?
Thanks.
--
Hmm...they have the Internet on COMPUTERS now!




Jim Cone

Performance Difference - LCase vs UCase?
 
Gary,
Option Compare Text makes all text comparisons case insensitive.
Regards,
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html


"Gary Keramidas"
<GKeramidasATmsn.com
wrote in message
jim i have a question on this and the option compare text

if i run the following code with option compare text under option explicit, i
get "the same"
if i remove option compare text, i get "different"

why the difference?

Sub test()
str1 = "Gary"
str2 = "gary"

If str1 Like str2 Then
MsgBox "the same"
Else
MsgBox "different"
End If
End Sub


--


Gary


"Jim Cone" wrote in message
...
If I were doing it I would use the "Like" operator...
If string1 Like string2 Then
This requires the "Option Compare Text" statement at the top of the module.

I doubt if there is any difference in the time required for Ucase vs. Lcase.
If time is an issue, then run each code version and time it..
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"MDW"
wrote in message
Hello,
I'm going to be comparing a bunch of string variables in a case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1) =
LCase(string2) Then..."
However, I'm going to be doing this thousands of times. It's irrelevant to
me if I compare the strings in upper case or lower. Is it any more "work" for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?
Thanks.
--
Hmm...they have the Internet on COMPUTERS now!




GKeramidas

Performance Difference - LCase vs UCase?
 
ok, got it thanks.

it eliminates the need to make the case the same to find a match.

--


Gary


"Jim Cone" wrote in message
...
Gary,
Option Compare Text makes all text comparisons case insensitive.
Regards,
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html


"Gary Keramidas"
<GKeramidasATmsn.com
wrote in message
jim i have a question on this and the option compare text

if i run the following code with option compare text under option
explicit, i
get "the same"
if i remove option compare text, i get "different"

why the difference?

Sub test()
str1 = "Gary"
str2 = "gary"

If str1 Like str2 Then
MsgBox "the same"
Else
MsgBox "different"
End If
End Sub


--


Gary


"Jim Cone" wrote in message
...
If I were doing it I would use the "Like" operator...
If string1 Like string2 Then
This requires the "Option Compare Text" statement at the top of the
module.

I doubt if there is any difference in the time required for Ucase vs.
Lcase.
If time is an issue, then run each code version and time it..
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"MDW"
wrote in message
Hello,
I'm going to be comparing a bunch of string variables in a
case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1)
=
LCase(string2) Then..."
However, I'm going to be doing this thousands of times. It's irrelevant
to
me if I compare the strings in upper case or lower. Is it any more "work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?
Thanks.
--
Hmm...they have the Internet on COMPUTERS now!





Tom Ogilvy

Performance Difference - LCase vs UCase?
 
I got Like as being slower then Ucase and Lcase which seemed to be the same,
but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on the
first character of each string). But it would to a case sensitive compare
and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a

case-insensitive
scenario. I will be using the tried and true method of "If LCase(string1)

=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant
to
me if I compare the strings in upper case or lower. Is it any more "work"

for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!






NickHK

Performance Difference - LCase vs UCase?
 
Tom,
I added an API version to the tests, but my figures agree broadly, but my
machine is a bit of a slow coach compared to yours:

'Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1 As String, ByVal lpString2 As String) As Long
'Without Option Compare Text
17.47266
16.51563
1.480469
5.390625
28.39063 'API
'With Option Compare Text
21.78125
20.87891
15.15234
5.359375
28.71094 'API

'Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiW" (ByVal
lpString1 As Long, ByVal lpString2 As Long) As Long
4.9375 'API

As long as you avoid all the ANSI<UNICODE conversions, the API seems
slightly faster than StrComp overall. As the OP wants case insensitive,
seems that "LIKE" may not be the best choice.

NickHK

"Tom Ogilvy" wrote in message
...
I got Like as being slower then Ucase and Lcase which seemed to be the

same,
but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on the
first character of each string). But it would to a case sensitive compare
and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a

case-insensitive
scenario. I will be using the tried and true method of "If

LCase(string1)
=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant
to
me if I compare the strings in upper case or lower. Is it any more

"work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to

impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!








GKeramidas

Performance Difference - LCase vs UCase?
 
tom:

what is b

b = (UCase(s1) = UCase(s2))

--


Gary


"Tom Ogilvy" wrote in message
...
I got Like as being slower then Ucase and Lcase which seemed to be the
same, but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on the
first character of each string). But it would to a case sensitive compare
and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a

case-insensitive
scenario. I will be using the tried and true method of "If
LCase(string1)

=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant
to
me if I compare the strings in upper case or lower. Is it any more
"work"

for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!







GKeramidas

Performance Difference - LCase vs UCase?
 
meant to ask what it should be dimmed as

anyway
here are my results

11.10986
11.33398
9.054932
4.460938

--


Gary


"GKeramidas" wrote in message
...
tom:

what is b

b = (UCase(s1) = UCase(s2))

--


Gary


"Tom Ogilvy" wrote in message
...
I got Like as being slower then Ucase and Lcase which seemed to be the
same, but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on the
first character of each string). But it would to a case sensitive
compare and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a
case-insensitive
scenario. I will be using the tried and true method of "If
LCase(string1)
=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant
to
me if I compare the strings in upper case or lower. Is it any more
"work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to
impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!







GKeramidas

Performance Difference - LCase vs UCase?
 
'option compare text
7.998047
8.172852
1.112793
4.482422

option compare text
11.10986
11.33398
9.054932
4.460938

--


Gary

--


Gary


"GKeramidas" wrote in message
...
meant to ask what it should be dimmed as

anyway
here are my results

11.10986
11.33398
9.054932
4.460938

--


Gary


"GKeramidas" wrote in message
...
tom:

what is b

b = (UCase(s1) = UCase(s2))

--


Gary


"Tom Ogilvy" wrote in message
...
I got Like as being slower then Ucase and Lcase which seemed to be the
same, but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on the
first character of each string). But it would to a case sensitive
compare and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a
case-insensitive
scenario. I will be using the tried and true method of "If
LCase(string1)
=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's
irrelevant to
me if I compare the strings in upper case or lower. Is it any more
"work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)?
Is
~5,000 conversions enough for any difference (if there is one) to
impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!








Andrew Taylor

Performance Difference - LCase vs UCase?
 
As the OP wants case insensitive,
seems that "LIKE" may not be the best choice.


Regardless of case-sensitivity and performance
considerations, "Like" is not suitable if any of
the strings could contain wildcard characters:
specifically *, ?, # or anything enclosed in
square brackets.

Andrew


NickHK wrote:
Tom,
I added an API version to the tests, but my figures agree broadly, but my
machine is a bit of a slow coach compared to yours:

'Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1 As String, ByVal lpString2 As String) As Long
'Without Option Compare Text
17.47266
16.51563
1.480469
5.390625
28.39063 'API
'With Option Compare Text
21.78125
20.87891
15.15234
5.359375
28.71094 'API

'Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiW" (ByVal
lpString1 As Long, ByVal lpString2 As Long) As Long
4.9375 'API

As long as you avoid all the ANSI<UNICODE conversions, the API seems
slightly faster than StrComp overall. As the OP wants case insensitive,
seems that "LIKE" may not be the best choice.

NickHK

"Tom Ogilvy" wrote in message
...
I got Like as being slower then Ucase and Lcase which seemed to be the

same,
but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on the
first character of each string). But it would to a case sensitive compare
and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a
case-insensitive
scenario. I will be using the tried and true method of "If

LCase(string1)
=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's irrelevant
to
me if I compare the strings in upper case or lower. Is it any more

"work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)? Is
~5,000 conversions enough for any difference (if there is one) to

impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!






Tom Ogilvy

Performance Difference - LCase vs UCase?
 
b was a variant since strcomp returns a long and the others were returning a
boolean. didn't want to introduce implied coercian.

--
Regards,
Tom Ogilvy


"GKeramidas" wrote in message
...
'option compare text
7.998047
8.172852
1.112793
4.482422

option compare text
11.10986
11.33398
9.054932
4.460938

--


Gary

--


Gary


"GKeramidas" wrote in message
...
meant to ask what it should be dimmed as

anyway
here are my results

11.10986
11.33398
9.054932
4.460938

--


Gary


"GKeramidas" wrote in message
...
tom:

what is b

b = (UCase(s1) = UCase(s2))

--


Gary


"Tom Ogilvy" wrote in message
...
I got Like as being slower then Ucase and Lcase which seemed to be the
same, but strcomp was considerably faster.

test was:
LCase
Ucase
Like
StrComp


7.984985
7.984009
8.609985
3.406006

that was with Option Compare Text turned on all the time.

If I turned it off, then Like was extremely fast (it could reject on
the first character of each string). But it would to a case sensitive
compare and give the wrong answer.

6.703003
6.703003
1.015015
3.406982

'Option Compare Text

Sub ABC()
Dim sngStart As Single, sngEnd As Single
Dim i As Long, s1 As String, s2 As String
Dim cnt As Long
cnt = 10000000
s1 = "ABCdef"
s2 = "abcDEg"
sngStart = Timer
For i = 1 To cnt
b = (UCase(s1) = UCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = (LCase(s1) = LCase(s2))
Next
Debug.Print Timer - sngStart

sngStart = Timer
For i = 1 To cnt
b = s1 Like s2
Next
Debug.Print Timer - sngStart



sngStart = Timer
For i = 1 To cnt
b = StrComp(s1, s2, vbTextCompare)
Next
Debug.Print Timer - sngStart

End Sub

--
Regards,
Tom Ogilvy


"NickHK" wrote in message
...
You also have the StrComp() function
Or go back to basics with
Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal
lpString1
As String, ByVal lpString2 As String) As Long

Can't say is fastest, but I would assume the API version.

NickHK

"MDW" wrote in message
...
Hello,

I'm going to be comparing a bunch of string variables in a
case-insensitive
scenario. I will be using the tried and true method of "If
LCase(string1)
=
LCase(string2) Then..."

However, I'm going to be doing this thousands of times. It's
irrelevant to
me if I compare the strings in upper case or lower. Is it any more
"work"
for
VBA to convert a string to all uppers vs all lowers (or vice versa)?
Is
~5,000 conversions enough for any difference (if there is one) to
impact
performance?

Thanks.
--
Hmm...they have the Internet on COMPUTERS now!











All times are GMT +1. The time now is 04:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com