= or .equals

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
Just a quick tip for all those out there who weren't aware how slow the = operator is for comparing strings when timed against the .equals function.

Are you ready for this........

The = operator is two orders of magnitude slower than the .equals function!!

Believe it or not the = operator uses old vb through com interop which means the string has to be marshalled out of managed memory into unmanaged memory.

This was news to me. I mean I used the = operator sometimes if i couldn't be bothered to type the extra bit.. lazy eh!! but now i am totally converted.
 
Whoa! Why on earth didnt they just make it synonymous?

What code did you use to test it? I wanna run the same in C#..
 
c# actually does a slightly better job. Only 4 times slower. Not to hot with c# but i think it may be something to do with the different way c# compares strings 'op_equality' or something like that.
 
personally, i'm still astounded that the compiler cannot do this itself, simply transliterating <leftside> = <rightside> into <leftside>.Equals(<rightside>)

it's a relatively simple find/replace if it has type-identified the participating tokens to be strings.

curious
 
Back
Top