; _______________________________________________________________________________________
;| |
;| ..:: Fresh IDE ::.. template project. |
;|_______________________________________________________________________________________|
;
; Description: FreshLib portable console application.
;
; Target OS: Any, supported by FreshLib
;
; Dependencies: FreshLib
;
; Notes:
;_________________________________________________________________________________________
include "%lib%/freshlib.inc"
@BinaryType console
include "%lib%/freshlib.asm"
; include your includes here.
MIN_STR_LEN = 16
MAX_STR_LEN = 1500
start:
InitializeAll
; invoke GetCurrentThread
; invoke SetThreadPriority, eax, THREAD_PRIORITY_TIME_CRITICAL
; first create an array of strings with different sizes:
mov ecx, MAX_STR_LEN
stdcall CreateArray, 4
mov edx, eax
stdcall AddArrayItems, edx, 1000000
stdcall FileWriteString, [STDOUT], <'Len: Sasha, Dword, ByteS', 13, 10>
.test_loop:
stdcall NumToStr, ecx, ntsUnsigned or ntsDec
stdcall StrCharCat, eax, $0a0d
push eax
stdcall FileWriteString, [STDERR], eax
stdcall StrDel ; from the stack
stdcall CreateTestArray, edx, ecx, 0
stdcall OutputVal, ecx, ': '
; stdcall Benchmark, edx, StrLen, ecx
; stdcall OutputVal, eax, ', '
stdcall Benchmark, edx, StrLenSasha, ecx
stdcall OutputVal, eax, ', '
stdcall Benchmark, edx, StrLenSashaHalf, ecx
stdcall OutputVal, eax, ', '
; stdcall Benchmark, edx, StrLenByte, ecx
; stdcall OutputVal, eax, ', '
stdcall Benchmark, edx, StrLenByte2, ecx
stdcall OutputVal, eax, $0a0d
stdcall FreeTestArray, edx
dec ecx
cmp ecx, MIN_STR_LEN
jae .test_loop
stdcall FreeMem, edx
FinalizeAll
stdcall Terminate, 0
proc CreateTestArray, .array, .strlen, .offset
.len dd ?
begin
pushad
mov edx, [.array]
mov eax, [.offset]
mov [edx+TArray.lparam], eax
mov ecx, [.strlen]
add ecx, [.offset]
add ecx, 16
mov [.len], ecx
mov esi, [edx+TArray.count]
lea edx, [edx+TArray.array]
.loop:
stdcall GetMem, [.len]
mov edi, eax
add edi, [.offset]
mov [edx], edi
add edx, 4
mov ecx, [.strlen]
mov al, 'a'
rep stosb
xor al, al
stosb
dec esi
jnz .loop
popad
return
endp
proc FreeTestArray, .ptrArray
begin
pushad
mov esi, [.ptrArray]
mov ecx, [esi+TArray.count]
mov edx, [esi+TArray.lparam]
lea esi, [esi+TArray.array]
.loop:
mov eax, [esi]
sub eax, edx
stdcall FreeMem, eax
add esi, 4
loop .loop
popad
return
endp
proc Benchmark, .test_array, .proc, .len
begin
pushad
mov esi, [.test_array]
mov ecx, [esi+TArray.count]
lea esi, [esi+TArray.array]
stdcall GetTimestamp
mov ebx, eax
.loop:
stdcall [.proc], [esi]
add esi, 4
dec ecx
jnz .loop
stdcall GetTimestamp
sub eax, ebx
mov [esp+4*regEAX], eax
popad
return
endp
proc OutputVal, .time, .char
begin
push eax
stdcall NumToStr, [.time], ntsUnsigned or ntsDec
push eax
stdcall StrCharCat, eax, [.char]
stdcall FileWriteString, [STDOUT], eax
stdcall StrDel ; from the stack
pop eax
return
endp
proc StrLenByte, .ptrString
begin
mov eax, [.ptrString]
dec eax
.loop:
inc eax
cmp byte [eax], 0
jne .loop
sub eax, [.ptrString]
return
endp
proc StrLenByte2, .ptrString
begin
push edi ecx
mov edi, [.ptrString]
or ecx, -1
xor eax, eax
repne scasb
lea eax, [edi-1]
sub eax, [.ptrString]
pop ecx edi
return
endp