Okay, if that's the case then you're better off omitting strlen() as it's unnecessary. Doing a length comparison seems like a quick way to determine string equality, but if you think about it, strlen() itself needs time to scan the string for 0.


*For example let's say you're comparing "abcdefgh" and "dcba"
---
Using the strlen method, strlen( "abcdefgh" ) and strlen( "dcba" ) must scan each string for the 0-terminator. Each byte must be compared to 0, totaling 14 compares.
---
Using the non-strlen method, you first compare 'a' and 'd' -- and since they do not match you return 0 only having done 1 compare.


*Now let's say you're comparing "abcde" and "abcde"
---
Using strlen method, strlen( "abcde" ) and strlen( "abcde" ) must scan each string for 0. 12 compares. Then being equal, they must be compared to eachother. 6 more compares. 18 total.
---
Using non-strlen method, first 'a' is compared to 'a' and found to be equal. Then 'b' to 'b' and so on... With each iteration you test one of the bytes for 0. (only one, since inequalities exit anyway, and if both bytes are 0 it's a match) Total 12 compares.
Posted on 2003-04-06 04:03:20 by iblis
oh i understand ;] i didnt say my way was right, i was just sayin, thats the way i was doing it. lol
Posted on 2003-04-06 16:09:22 by xkardisx