This is a testing tool I wrote to profile my functions, it is still in the very first stages
of development so I cannot be sure it is of any real use.

It is based on the article on C/C++ user journal 'A Testjig Tool for Pentium Optimization' 
by Steve Durham (December 1996).

What the component do is to count the number of processor cycles used to executed 
a test function.
This is a good way of profiling algorithms because it is independent to the speed of
the processor.

The component uses a Pentium instruction RDTSC that read a counter (pentium time stamp 
counter) containing the number of cycles executed since power up.

To Install
----------
Put uPentium.pas and uMemObj.pas into a directory and Install uPentium.Pas as a new 
component.
There is no resource file yet so on your menu it will look like something you already have.

Then if you want to see a demo open the project Pentiumtest.dpr into the Delphi IDE.


What Does it really do.
-----------------------

Create a new form, select the Pentium component you just installed and place it on the 
form.
Select the pentium component and click on events, double-click on OnHeatCache and
add the code you want to be executed before the test run, like allocating memory or 
setting variables, in order to have the data 32-byte aligned the Pentium Object has
a function AllocateMemory(size Longint) that will make sure your data is ready to be
loaded into the cache (aligned).
Another function HeathVariable(var hvar; Size : integer) is not fully tested but the
intention is to to load into the cache your variables as well, to do that just pass
your variable name and his type size (eg HeathVariable(x, sizeof(integer)) ).
All the memory you allocate can be accessed using GetPointer(int num), it will return the
num-th portion of memory you allocated (zero based).

Back to the object inspector double-clik on OnEndTest and add the code you want to be 
executed after the test function is executed; to free the memory you allocated with
AllocateMemory use FreeAll().

Finally double-click on OnTestFunction and type your code to test.


To execute the test you can either set the Active field to True or run the RunTest() 
function.
(Run-time only at the moment)

The result will be in the TimeCount field.

It seems a lot in writing but it should be really easy to use in fact (if it works).


The Pentium Class :

PUBLIC MEMBERS
    HotMemory : TList;    <- This is a public accessible Tlist object with all the
				pointers to your blocks of memory

    function AllocateMemory(size : longint) : Pointer; <- Use this to allocate 32-byte 
							aligned blocks of memory

    procedure HeathVariable(var hvar; Size : integer);  <- Not fully tested but should
							put variables into cache too

    function GetPointer(index : integer) : pointer; <- return the pointer to memory block


    function GetSize(index : integer) : longint; <- return the size of memory block

    procedure FreeAll; <- Free all memory blocks

    procedure RunTest; <- Run the function to profile

PUBLISHED MEMBERS
    property Active :  <- Set it to True to run the function to profile.

    property ColdCache : <- Set it to true and the cache will be filled with random garbage
				instead of your data, with this you can test function 
				in the worst possible situation because the pentium will
				have to fetch the data from main memory. 

    Property TimeCount : <- It contains the results in number of machine cycles.

    property NoInterrupt : <- Set it to True and the interrupts will be disabled during the
				execution of the test function (not really sure if this
				is useful).


EVENTS 

    property OnCacheHeath : <- Called before the test is executed
    property OnTestFunction : <- Function to profile
    property OnEndTest : <- Called after the test is executed



The component can be improved in many ways, please send comments to :

Massimo Bardetti
www.primenet.com/~bigben
bigben@primenet.com