home *** CD-ROM | disk | FTP | other *** search
-
- The Zen Timer Library
- =====================
-
- This is a memory model independant 'C' callable library for timing code
- fragments with an accuracy of better than 10 microseconds (less when using
- the long period zen timer). The code was originally written by Michael Abrash
- for his book "Zen of Assembly language - Volume I, Knowledge". I modified the
- code and made it into a 'C' callable, memory model independant library and
- added the utility routines LZTimerCount() and PZTimerCount() to return an
- unsigned long integer representing the timed count in microseconds.
-
- Using the timer
- ---------------
-
- To use the timer, isolate the piece of code you wish to time and bracket
- it with calls to PZTimerON (LZTimerON respectively) and PZTimerOff (LZTimerOff
- respectively). You can either call PZTimerReport (LZTimerReport respectively)
- which will display the count on the standard output device, or you can call
- PZTimerCount (LZTimerCount respectively) to obtain the count use it from
- within your C program. For example:
-
- int i;
-
- void main(void)
- {
- LZTimerOn();
- for (i = 0; i < 20000; i++)
- i = i; /* Do some work */
- LZTimerOff();
- LZTimerReport();
- }
-
- shows the simplest way to use the timer. The file "main.c" contains code
- to test both the precision and long period timers, so have a look at it to
- get an idea of how to use the timer.
-
- The precision timer gives the most accurate results, but can only be
- used for code that executes in less than 54ms, and you CANNOT turn
- interrupts on while the code is being timed (if you code goes into an
- infinite loop while using the precision timer you will need to reach for
- that elusive reset switch :-). Personally the long period timer is
- accurate enough for me and I generally use this exclusively.
-
- One point to note when using the long period time however, interrupts
- are ON while this timer executes. This means that every time you hit a key
- or move the mouse, the timed count will be longer that normal. Thus you
- should avoid hitting any keys or moving the mouse while timing code fragments
- if you want highly accurate results. It is also a good idea to insert a
- delay of about 1-2 seconds before turning the long period timer on if
- a key has just been pressed by the user (this includes the return key used
- to start the program from the command line!). Otherwise you may measure the
- time taken by the keyboard ISR to process the upstroke of the key that was
- just pressed.
-
- Notes on compiling the library
- ------------------------------
-
- The library was compiled using Borland C++ 3.0 and Turbo Assembler 3.0.
- The code will NOT assemble under MASM, since it is written using
- Turbo Assemblers IDEAL mode syntax. You will need to modify it significantly
- to get it to assemble under MASM.
-
- I write all my code with 4 space tabs, so if you wish to view the source
- code the way I see it :-), you will need to set you editor to 4 space tabs
- (even the .ASM files use 4 space tabs). Alternatively you can view the
- source code files with "m.exe" included in the archive, a more replacement
- that I have written. It automatically expands tabs to 4 spaces (or any
- size you like with the -t option).
-
- The long period Zen Timer has been assembled to run on all computers,
- including the IBM PS/2 range of computers whose timer chips are not
- 100% compatible with the 8253. If you have read Michael's book, or you
- have had a look at the source code for the long period timer, you will
- know that you can re-assemble it with the PS2 equate set to 0 which will
- give more accurate results on computers with 100% compatible 8253 timer
- chips (note that this does not affect the precision Zen Timer - this works
- on all computers). I personally leave the PS2 equate set to 1, so that my
- code will work on any computer. Occasionally (and this is very rare - it
- has happend only once in the 3 odd months I have been using this code),
- the timer count will be out by 54 ms, but I find that I can live with
- this.
-
- The makefile included in the distribution is set up to build the library
- on my computer, but it should be very easy to modify for another installation
- (it took me five minutes to move it from my old 286 machine to my new
- 486/33 with a larger hard disk!). Consult the makefile to see how to do it.
-
- I have included the turboc.cfg file that I use to compile code from
- the command line using Borland C++ 3.0. You will need to modify the include
- file and library file directories for your system. If you have an earlier
- version of Borland C++, or Turbo C++ then most of the optimisation switches
- will not be valid.
-
- Files in this archive
- ---------------------
-
- debug.h - Header file for portable code
- lztest.asm - Shell program for timing assembler code
- lztime.bat - Batch file to automate assembler code timing
- lztimer.asm - Long Period Zen Timer source code
- m.exe - Replacement for more (with tab expansion!).
- main.c - Sample program source code
- makefile - Makefile for the Zen Timer library
- model.mac - Memory model independant macros for TASM
- pztest.asm - Shell program for timing assemble code
- pztime.bat - Batch file to automate assembler code timing
- pztimer.asm - Precision Zen Timer source code
- read.me - What you are reading :-)
- turboc.cfg - Configutation file for Borland C++ 3.0
- ztimer.h - Header file for the library
- ztimer.lib - The library itself
- movtst.asm - Sample assember test code
- movtst2.asm - Sample assembler code to overflow PZTimer
-
- Turbo Pascal related files:
-
- lztimer.pas - Source code for the TP interface unit
- lztimer.tpu - Prebuilt Turbo Pascal unit for the interface
- main.pas - Turbo Pascal version of sample test code
-
- Turbo Pascal Notes
- ------------------
-
- Duncan Murdoch kindly took the time to build a Turbo Pascal interface
- for the Zen Timer library, which requires Turbo Pascal 6.0 or above (so
- he tells me :-). Following are his notes on the interface unit.
-
- The interface to the assembler routines is written to be as simple as
- possible. Void functions became procedures; the count functions returning
- unsigned long integers return signed longints. Leading underscores were added
- to the procedure/function names to match the assembler source.
-
- Because of limitations in the linker, TP versions prior to 6.0 will
- *not* be able to use this unit.
-
- Interfaced routines:
-
- procedure _PZTimerOn; Starts precision timer.
-
- procedure _PZTimerOff; Stops precision timer.
-
- procedure _PZTimerReport; Reports result of precision timing to
- standard output.
-
- function _PZTimerCount : longint; Returns microsecond count for precision
- timer. May overflow, and return negative
- value. Value -1 signals timer overflow.
-
- procedure _LZTimerOn; The LZ routines are as above, but for
- procedure _LZTimerOff; the long period timer.
- procedure _LZTimerReport;
- function _LZTimerCount : longint;
-
- I have asked Duncan if it is possible for Turbo Pascal to handle
- unsigned long integers, since times greater than about 35 minutes will
- become negative when interpreted as a signed long integer. If this is not
- possible, then you will have to take this into account when using the
- library.
-
- Well, thats it. I hope you find this library useful (I use it all the time
- to time my graphics routines). You can contact me with comments, queries and
- bug fixes as show below:
-
- Internet:
-
- Kendall Bennett kjb@godzilla.cgl.citri.edu.au
- Duncan Murdoch (Turbo Pascal unit) dmurdoch@watstat.uwaterloo.ca
-
- Snail mail: Kendall Bennett
- 15 Stevenson Street
- Kew Melbourne Victoria 3101
- Australia
-
-