function to test:.486
.model flat,stdcall
.code
proc_4 proc string
mov eax,string
sub eax,4
@@: add eax,4
mov edx,[eax]
lea ecx,[edx-01010101H]
not edx
and ecx,edx
and ecx,80808080H
jz @B
bsf ecx,ecx
shr ecx,3
sub eax,string
add eax,ecx
mov ecx,eax
ret
proc_4 endp
end
jwasm -bin proc_4.asm
flag_0 equ 0
flag_1 equ 0
flag_2 equ 0
flag_3 equ 1
flag_4 equ 1
flag_5 equ 1
flag_6 equ 1
proc_0 equ crt_strlen
proc_1 equ szLen
proc_2 equ MbStrLen
proc_3 db "strlen\proc_3.bin",0
proc_4 db "strlen\proc_4.bin",0
proc_5 db "strlen\proc_5.bin",0
proc_6 db "strlen\proc_6.bin",0
info_0 db "crt_strlen",0
info_1 db "MASM32 - szLen() ",0
info_2 db "MasmBasic MbStrLen Len() - SSE",0
...
pushargs macro
push str_x
endm
; get the cycle count for each algo
test_algo macro x, loopcount
if flag_&x&
lea edx,proc_&x&
else
mov edx,proc_&x&
endif
invoke timeit,edx,0,flag_&x&,loopcount,x,addr info_&x&
endm
.code
readit proc uses ebx edi fname
sub edi,edi
invoke CreateFile,fname,80000000h,0,0,3,0,0
.if eax != -1
mov ebx,eax
push 0
mov edx,esp ; lpNumberOfBytesRead
invoke ReadFile,ebx,addr proc_x,4096,edx,0
test eax,eax
pop edi
.if ZERO?
sub edi,edi
.endif
invoke CloseHandle,ebx
.endif
mov eax,edi
ret
readit endp
timeit proc uses ebx esi edi p,plen,ptype,count,id,info
.if ptype
invoke readit,p
mov plen,eax
lea esi,proc_x
test eax,eax
jz error1
.else
mov esi,p
.endif
counter_begin 1000, HIGH_PRIORITY_CLASS
mov edi,count
mov ebx,esp
.while edi
pushargs
call esi
mov esp,ebx
dec edi
.endw
counter_end
printf("%d\tcycles - %d (%3d) %d: %s\n",eax,count,plen,id,info)
toend:
ret
error1:
printf("error reading %s\n",info)
jmp toend
timeit endp
151336 cycles - 50 ( 0) 0: crt_strlen
244234 cycles - 50 ( 0) 1: MASM32 - szLen()
47350 cycles - 50 ( 0) 2: MasmBasic MbStrLen Len() - SSE
157571 cycles - 50 ( 86) 3: AgnerFog
140117 cycles - 50 ( 49) 4: AgnerFog unaligned
340870 cycles - 50 ( 94) 5: Dave
38961 cycles - 50 ( 45) 6: strlen SSE