which is better

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

thanks,
rodchar
 
I'd say that there is a performance hit with the first, since it's doing 2
method calls. You'll hardly notice it though (unless you do it a *lot*) so
go with whatever feels best.

/claes
 
Rodchar,

In my opinion is the second the most optimized. It reads easier.

However the slight performance benefit will be as well with the second.

You need in the second only one split command to be executed, in the first
that is two.

Just my thought,

Cor
 
The second one is faster by about 50%.

But this is faster by roughly 68%.
ar = str.Split(" "c)
result = ar(0) & " " & ar(1)
 
rodchar said:
is there a difference when saying:

myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)

-or

myArrary = Split(_dr.TCADR1, " ")
myString = myArray(0) & " " & myArray(1)

I suggest to choose the second option because it won't perform a useless
'Split' operation.
 
rodchar,
In addition to the other comments.

| is there a difference when saying:
To the computer, no there is no real difference. Although you are calling
Split twice which may have a minor impact on performance speed & GC
pressure. Unless the statement is in a tight loop, I would expect the
performance impact & GC pressure to be relatively minor...


More importantly: To humans (including yourself in 6 months) there is a huge
difference!

I would expect most developers would find the second to be more immediately
obvious what you are trying to do, in other words the "intent of the code".
While the first reading the code one has to stop & think about what's
happening...



--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| hey all,
|
| is there a difference when saying:
|
| myString= Split(_dr.TCADR1, " ")(0) & " " & Split(_dr.TCADR1, " ")(1)
|
| -or
|
| myArrary = Split(_dr.TCADR1, " ")
| myString = myArray(0) & " " & myArray(1)
|
| thanks,
| rodchar
 
Back
Top