[comp.sys.atari.st] timer

jstorey@wpi.wpi.edu (John R Storey) (01/13/90)

I'm writing a C program and have a small problem - I want to time how long
a call to the Random ( ) XBIOS function.  The problem is that I can't figure
out how to time it in increments smaller than 2 seconds.  

steve@thelake.mn.org (Steve Yelvington) (01/16/90)

[In article <6667@wpi.wpi.edu>,
     jstorey@wpi.wpi.edu (John R Storey) writes ... ]

> I'm writing a C program and have a small problem - I want to time how long
> a call to the Random ( ) XBIOS function.  The problem is that I can't figure
> out how to time it in increments smaller than 2 seconds.  

The Random() xbios function executes too fast to be timed even with a
clock that ticks 200 times a second. You could call it 1000 times and then
compute the average, but you'd also be timing the loop that called
Random().

The 200-Hz system timer is in protected memory and accessible only in
supervisor mode. The dLibs C library (the one that comes with the Sozobon
compiler) has functions that make this easy. The program below
demonstrates these functions (with an example that takes a few
milliseconds to complete). If your compiler doesn't have start_timer() and
time_since(), you can find the sources in the dLibs timer.c file.

To compile this with Sozobon, cc it with the -f flag (floating point).

Incidentally, I got these results:

0.075000 with no scrolling (starting with a clear screen).
0.175000 if the program had to scroll the display.
0.445000 when I redirected it to a file.

    0/ cut here
=== 0\============================================================

#include <time.h>
#include <osbind.h>

main()
	{
	clock_t t;
	float tt;

	/* record the starting time */
	start_timer(&t);	

	/* do something that takes some time */
	printf("Ob lah dee, ob lah dah\n");
	printf("life goes on, brah!\n");
	printf("La, la, la, la life goes on....\n");

	/* get the result */
	tt = (float) time_since(&t);

	/* print a report */
	printf("\n\nOb lah dee took %f second(s).\n", tt / CLK_TCK);
	}

    0/ cut here
=== 0\============================================================

-- 
   Steve Yelvington at the (all-too-warm and windy) lake in Minnesota
   UUCP path: ... umn-cs.cs.umn.edu!thelake!steve

greg@sj.ate.slb.com (Greg Wageman) (01/16/90)

Opinions expressed are the responsibility of the author.

In article <6667@wpi.wpi.edu> jstorey@wpi.wpi.edu (John R Storey) writes:
>I'm writing a C program and have a small problem - I want to time how long
>a call to the Random ( ) XBIOS function.  The problem is that I can't figure
>out how to time it in increments smaller than 2 seconds.  

You don't say which compiler you're using, so this may not apply to
you.  Mark Williams C provides a function called "clock()", which
returns the number of clock ticks since the system was booted.  The
constant CLK_TCK encodes the number of ticks/second.

It so happens that the clock() functions uses the 200hz system timer,
so if you save the value returned by clock() (an unsigned LONG) before
and after the Random() call, and difference them, you will get the
number of clock ticks elapsed, more or less.  Integer division by
CLK_TCK will give you elapsed time in seconds; modulo CLK_TCK gives
you the remainder in 5-millisecond ticks.

Copyright 1990 Greg Wageman	DOMAIN: greg@sj.ate.slb.com
Schlumberger Technologies	UUCP:   {uunet,decwrl,amdahl}!sjsca4!greg
San Jose, CA 95110-1397		BIX: gwage  CIS: 74016,352  GEnie: G.WAGEMAN
 Permission is granted for reproduction provided this notice is maintained.