here is faster lstrcmp:?  :)


Please terminate any high-priority tasks and press ENTER to begin.

lstrcmp? Tests:

lstrcmp - original: 19314 clocks; Return value: 1
lstrcmp - kunt0r? : 957 clocks; Return value: 24832
lstrcmp - Lingo? ?: 501 clocks; Return value: 1

Press ENTER to exit...


Regards,
Lingo
Attachments:
Posted on 2005-08-20 05:56:48 by lingo12
Hi lingo, does your routine follow the standard of < 0, 0, > 0 return values?

Oh, and when uploading zips, would you mind addting date/time to the filename? There's sometimes issues with caching when attachments get updated and such :/
Posted on 2005-08-20 08:21:54 by f0dder
Nice, lingo :) I get (p4 1.5GHz 768megs mem)


lstrcmp - original: 18064 clocks; Return value: 1
lstrcmp - kunt0r  : 868 clocks; Return value: 24832
lstrcmp - Lingo  : 492 clocks; Return value: 1



Hi lingo, does your routine follow the standard of < 0, 0, > 0 return values?


Looks like it from the source


...
xor eax, eax ; 2 strings are equal
...
mov eax, 1 ; 2 string is less then 1 string
...
or eax,-1 ; 1 string is less then 2nd string
Posted on 2005-08-20 08:48:39 by stormix
lstrcmp - original: 13029 clocks; Return value: 1
lstrcmp - kunt0r? : 864 clocks; Return value: 24832
lstrcmp - Lingo? ?: 388 clocks; Return value: 1

do i win?? :mrgreen:
Posted on 2005-08-20 09:00:29 by Tola

lstrcmp - original: 26859 clocks; Return value: 1
lstrcmp - kunt0r? : 647 clocks; Return value: 24832
lstrcmp - Lingo? ?: 379 clocks; Return value: 1

instead of using lstrcmp as a base to compare with, which calls CompareStringA
and hence is ~20 times slower, i suggest something simple as this:

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
StrCmp proc pStr1:DWORD,pStr2:DWORD
mov edx,;Str1
mov eax,;Str2? ? ? ? ? ? ?
@@: mov cl,
inc edx
mov ch,
inc eax
sub cl,ch
jnz @F
test ch,ch
jnz @B
xor eax,eax
ret 2*4
@@: sbb eax,eax
lea eax,
ret 2*4
StrCmp endp
OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF


lstrcmp? Tests ( reversed str1 & str2 ):

lstrcmp - StrCmp? : 1249 clocks; Return value: -1
lstrcmp - kunt0r? : 643 clocks; Return value: 40704
lstrcmp - Lingo? ?: 378 clocks; Return value: -1

Tested on P2-C-533MHz - Do I win? :mrgreen:
Posted on 2005-08-20 09:04:37 by drizz
AMD64 3500 results:

lstrcmp - original: 24776 clocks; Return value: 1
lstrcmp - kunt0r  : 727 clocks; Return value: 24832
lstrcmp - Lingo  : 327 clocks; Return value: 1

...for teh win!111! ;)

Posted on 2005-08-20 09:26:16 by f0dder
AMD64 3400+ on 32-bit Windows


lstrcmp - original: 11339 clocks; Return value: 1
lstrcmp - kunt0r  : 728 clocks; Return value: 24832
lstrcmp - Lingo  : 329 clocks; Return value: 1
Posted on 2005-08-20 18:07:42 by SpooK
Here's results from a 1.5GHz Pentium-M with XP-SP2

lstrcmp - original: 25127 clocks; Return value: 1
lstrcmp - kunt0r  : 666 clocks; Return value: 24832
lstrcmp - Lingo  : 358 clocks; Return value: 1


I've used taskmgr to set process prioroity to realtime both on this test and the one on my AMD64.
Posted on 2005-08-20 18:20:36 by f0dder
Thinkpad T23

Pentium3M 1.13Ghz (also with WinXP SP2)

lstrcmp - original  : 18283 clocks ; Return value: 1
lstrcmp - kunt0r  : 648 clocks ; Return value: 24832
lstrcmp - Lingo    : 380 clocks ; Return value: 1
Posted on 2005-08-20 18:47:36 by x86asm
All those "align 16" are giving me erros:

error A2189: invalid combination with segment alignment : 16


How would I get around with this?
Posted on 2005-08-20 20:04:06 by Lenin
Try using ".686" at the start of your code.
Posted on 2005-08-20 21:45:22 by roticv
Windows XP Professional 64-bit Edition (practically the same as my 32-bit test).


lstrcmp - original: 12699 clocks; Return value: 1
lstrcmp - kunt0r  : 728 clocks; Return value: 24832
lstrcmp - Lingo  : 328 clocks; Return value: 1
Posted on 2005-08-21 03:28:39 by SpooK
Windows Xp Home Sp2 , P4 2.66 GHz

lstrcmp - original: 16788 clocks; Return value: 1
lstrcmp - kunt0r  : 846 clocks; Return value: 24832
lstrcmp - Lingo  : 463 clocks; Return value: 1
Posted on 2005-08-21 07:24:36 by Vortex
Windows XP Professional SP2, AMD64 3400+


lstrcmp - Lingo    : 608 clocks; Return value: -1
lstrcmp - Lingo Old : 616 clocks; Return value: -1
Posted on 2005-08-21 14:42:30 by SpooK
Thank you guys
for the wonderful results... :)

Here is a bit faster version on my P4 3.6 GHz
with WinXP Pro SP2


lstrcmp? Tests:

lstrcmp - Lingo? ? ?: 875 clocks; Return value: -1
lstrcmp - Lingo Old : 942 clocks; Return value: -1

Press ENTER to exit...


Regards,
Lingo
Attachments:
Posted on 2005-08-22 19:01:42 by lingo12
The code looks good, and it returns correct results, bigger/smaller/equal, but you shouldn't really call it an lstrcmp since it doesn't follow the same return values.

From the SDK

The function returns the difference of the values of the first unequal characters it encounters. For example, lstrcmp determines that "abcz" is greater than "abcdefg" and returns the difference of z and d.


Just a suggestion, make it a straight boolean compare true or false, because the 1 and -1 returns are somewhate useless (knowing that a string is bigger or smaller without knowing by what value has little to no uses).

If your going for speed, an unroll of the initial comparison for equality would most likely improve performance by around, for a 2x unroll 15-20%, for a 4x unroll 25%.

Again very nice code, looks like something an optimizing compiler like GCC would come up with.
Posted on 2005-08-22 19:55:21 by r22

Just a suggestion, make it a straight boolean compare true or false, because the 1 and -1 returns are somewhate useless (knowing that a string is bigger or smaller without knowing by what value has little to no uses).

It's quite useful when sorting strings... iirc the libc strcmp only says <0, 0, >0, and doesn't mention difference between the chars - and it's still very useful.
Posted on 2005-08-22 19:59:14 by f0dder
wow , it seems my XP 1900+ (underclocked to 1200Mhz) faired a bit better on your original code (unless you changed somthing):

lstrcmp  Tests:

lstrcmp - original: 5568 clocks; Return value: 1
lstrcmp - kunt0r  : 801 clocks; Return value: 24832
lstrcmp - Lingo  : 364 clocks; Return value: 1

Press ENTER to exit...
Posted on 2005-08-22 20:46:35 by x86asm

lstrcmp - Lingo    : 615 clocks; Return value: -1
lstrcmp - Lingo Old : 616 clocks; Return value: -1
Posted on 2005-08-22 22:07:07 by SpooK
Thank you Spook and x86asm :) :)

f0dder and? r22,
"Just a suggestion, make it a straight boolean compare true or false, because the 1 and -1 returns are somewhate useless (knowing that a string is bigger or smaller without knowing by what value has little to no uses)."


For me is not a big deal to add some functionality (see the attached file)
but is very interesting the fact all calls to lstrcmp addr str1,addr str2
return -1, 0, 1 (see prev page and tests for lstrcmp - original:)


"If the string pointed to by lpString1 is less than the string pointed to by lpString2, the return value is negative. If the string pointed to by lpString1 is greater than the string pointed to by lpString2, the return value is positive. If the strings are equal, the return value is zero.

The function returns the difference of the values of the first unequal characters it encounters. For example, lstrcmp determines that "abcz" is greater than "abcdefg" and returns the difference of z and d. "


Here is the new version with additional functionality
Example:
str1? db "abcdefg", 0
str2? db "abcz", 0

So, z=122? d=100? and
z-d=122-100=22
and minus because str1 is less then str2


lstrcmp? Tests:

lstrcmp - Lingo? ? ?: 20 clocks; Return value: -22
lstrcmp - Lingo Old : 29 clocks; Return value: -1

Press ENTER to exit...


Regards,
Lingo
Attachments:
Posted on 2005-08-23 21:28:06 by lingo12