Zprofiler :  a tool for optimizing Delphi programs on Pentium computers. version 2.20
-------------------------------------------------------------------------------------
This utility component enables the assessment of execution times of code fragments 
with a 0.01 microsecond resolution. It is based on the cpu clock of Pentium computers,
using the RDTSC instruction.

Changes since version 2.1
    internal dataformat changed from dword to comp
Changes since version 2.0
    error that occurs when timing recursive functions has been fixed
    property Visible as been added
    
Running the demo
The demo does not require installation of the component ! In de Delphi IDE : open 
demo.dpr and run it.

Installing the component :
Put the files z_prof.pas , z_prof.dfm and z_prof.dcr in one of your library directories,
and install z_prof as usual. The component Zprofiler will appear on the samples page of
the palette.

Usage :
Using the component is extremely simple. Drop zprofiler on your form, and a modeless 
window will appear with a grid containing the timing results. 
There is only one method you need to use for marking enclosed timing blocks :
profile.mark(nr:integer; aactive:boolean); 
             nr : number of the code fragment , currently maximal 20 blocks
             aactive : start/ stop marking a code fragment
(NB prefereably, use the global profile pointer instead of zprofiler1 generated by Delphi)
If you want to put markers in project units that have no form file, add the z_prof unit in
its uses section, and instanciate the component dynamically if that has not yet been done
elsewhere yet. The demo applies dynamic instantiation.  

Example :
     profile.mark(1,true);      start timing fragment 1
     <some code  >              the program code under investigation
     profile.mark(1,false);     stop timing fragment 1


Details :
The markers act globally and are all owned by the mainform, accessible via the pointer 
"profile". Only one instance of the resultgrid be executed. Thus, there is no point to
dropping more than one zprofiler on a form(no harm either). You can drop them on secondary
forms as an easy way of updating the uses section with z_prof. 
When you need more markers than the standard 20, increase the nmarks constant in z_prof.pas
and recompile. The codemarkers act independently from each other.
This version allows timing of designmode operations as well. Set the published property :
VisibleInDesignMode to true, and the grid will appear in designmode as well. Thus the 
behaviour of custommade components can be  evaluated in designmode. Of course, the markers 
must be hardcoded in their sources. You can hide and show the resultgrid in runtime by 
assigning false/true to the Visible property.
If you prefer to instantiate the component dynamically, put z_prof in "uses" and make the 
call : tzprofiler.create(application.mainform); {no reason for storing the resulting pointer}
          

Technical information :
The resolution of  0.01 microseconds is not completely realistic. The component corrects for
its own overhead as good as possible but I experience on my computer (233MHz Pentium) a 
reproducible residual 0.06 microseconds that I ascribe to uncompensated timelosses in the 
mark() method. Furthermore, there are occasional time lapses that are probably due to tasks
in the operating system, or caused by cpu (cache) operations. If you want to time a very 
short interval, the column that displays the fastest time is probably the most "clean".
However, the mean execution time is a better estimator of practical purposes.
NB it only works on Pentiums, since it relies on the RDTSC instruction that is only 
available on a pentium cpu.
Don't forget to remove the component after developementphase is finished !


References
Jon Shemitz, Using RDTSC for benchmarking code on pentium computers, 
       http://www.midnightbeach.com/jon/pubs/ (June 1996)
Steve Durham,  C/C++ user journal  'A Testjig Tool for Pentium Optimization' (Dec 1996).
Massimo , uPentium freeware component, downloaded from Delphi Super Page (June 1997)

Acknowledgement
Robert Rossmair, for his suggestion about introducing the comp data format and (not yet
       implemented) help file.
 

Copyright
Use it as you like. Feel free to adapt it to your needs, but if you publish it, please 
make proper references. If you have suggestions or improvements,  send me an email :
antonie.baars@wxs.nl
Antonie Baars, May 24, 1998