Testbug's speed tests

Comparing Win32 APIs

Memory heap tests

These tests are intended to compare the "Heap" APIs, (HeapCreate, HeapDestroy, HeapFree, etc.) with the "Virtual" APIs, (VirtualAlloc, VirtualFree etc). To my mind the Virtual functions are easier to use and they seem to be much quicker too. The Heap functions have continued from 16-bit Windows code and internally the type of memory which is made by the two sets of functions is entirely different. The system keeps track of "Virtual" memory internally (whereas Heap memory has a header).
Each test is repeated 200 times and the "tick" is tested using QueryPerformanceCounter.

This first test simply creates 4K of memory (which may be referred to as a "page" on most systems) and then destroys it using the Heap functions:-

PUSH 4096             ;maximum size of memory
PUSH 4096             ;amount allocated now
PUSH 0                ;flag
CALL HeapCreate
OR EAX,EAX            ;see if false finish
JZ >L10
MOV [hHeap2],EAX
PUSH [hHeap2]         ;handle to heap
CALL HeapDestroy
OR EAX,EAX            ;see if false finish
The second test is the same as the first but creates and destroys 64K of memory (the value 10000h is passed to HeapCreate).
The third test is the same but creates and destroys 256K of memory (in this case the value of 40000h is passed to HeapCreate).

In the fourth test 12K of memory is created as virtual memory but it is not initially allocated to physical memory. Then 4K of the 12K is allocated and finally all the memory is destroyed:-

PUSH 3000h            ;12K maximum size of memory
PUSH 0                ;amount allocated now
PUSH 0                ;flag
CALL HeapCreate
OR EAX,EAX            ;see if false finish
JZ >L10
MOV [hHeap2],EAX
PUSH 1000h            ;4K number to allocate now
PUSH 0                ;flag
PUSH [hHeap2]         ;handle to heap
CALL HeapAlloc
OR EAX,EAX            ;see if false finish
JZ >L10
PUSH [hHeap2]         ;handle to heap
CALL HeapDestroy
OR EAX,EAX            ;see if false finish (temp)
The fifth test is the same as the fourth except that 72K (12000h) of memory is created, then 64K (10000h) is allocated and finally all the memory is destroyed.
In the sixth test 328K (48000h) of memory is created, then 256K (40000h) is allocated and finally all the memory is destroyed:-

In the seventh test, HeapCreate is used to create growable memory. 4K of memory is then allocated using HeapAlloc, then all memory is destroyed:-

PUSH 0                ;make growable memory
PUSH 0                ;amount allocated now
PUSH 0                ;flag
CALL HeapCreate
OR EAX,EAX            ;see if false finish
JZ >L10
MOV [hHeap2],EAX
PUSH 4096             ;number to allocate now
PUSH 0                ;zero memory
PUSH [hHeap2]         ;handle to heap
CALL HeapAlloc
OR EAX,EAX            ;see if false finish
JZ >L10
PUSH [hHeap2]         ;handle to heap
CALL HeapDestroy
OR EAX,EAX            ;see if false finish
In the eighth test, 4K of memory is created using VirtualAlloc then it is destroyed:-
PUSH 4h               ;flag read and write access
PUSH 1000h            ;commit memory flag
PUSH 1000h            ;size of memory to be committed
PUSH 0                ;where to put memory
CALL VirtualAlloc
OR EAX,EAX            ;see if false finish
JZ >L10
MOV [hHeap2],EAX
PUSH 8000h            ;release flag
PUSH 0                ;all memory to go
PUSH [hHeap2]         ;address of memory area
CALL VirtualFree
OR EAX,EAX            ;see if false finish
The ninth test is the same as the eighth test, except that 64K of memory is created using VirtualAlloc by passing 10000h as the second parameter, then the memory is destroyed.
The tenth test is the same again except that 256K of memory is made by passing 40000h as the second parameter and then the memory is destroyed.