Article 164447 of comp.os.vms:

Look's like my question started an interesting thread ...

Now, after reading all the helpful answers, I did some testing of my own.
The following code works for me under VMS6.2, DECC 5.2.
( I didn't find <hwrpbdef.h> mentioned by Stephen 'Hoff' Hoffman
anywhere, so cpu_speed looks somewhat funny...)
I don't claim this is good C-code (I am a PASCAL programmer),
but it works for me. You may find it usable too. Standard disclaimers apply.

Now the interesting thing is, that repeatedly using RPCC for timing purposes
gives quite a range of answers for the same simple loop.
Anybody have an answer for that ?

Anyway, I would like to thank all of you who took the time to answer my 
question (and many more).

Uli Kabatek


---- cut here ----
$ cc/deb/noopt timing
$ lin/deb/sysexe timing, sys$input/opt
sys$loadable_images:sysdef.stb/selective
$ delet/nolog timing.obj.*
$ exit

---- cut here ----

#include <builtins.h>
#include <stdio.h>

extern int     *hwrpb$iq_cycle_count_freq;	/* link w. sysdef.stb	*/
extern __int64 exe$gpq_hwrpb;			/* link /sysexe		*/

static int cpu_speed(void)
{
    char *c_addr;
    int  *i_addr;
    int  speed, offset;

    c_addr = (char *) exe$gpq_hwrpb;
    offset = (int) &hwrpb$iq_cycle_count_freq;
    i_addr = (int *) (c_addr + offset);
    speed  = *i_addr;

    return speed;
}

typedef union
{
    __int64  q;
    unsigned u[2];
} rpcc;

static void start_timing( unsigned int *start )
{
    rpcc val, sum;

    val.q = __RPCC();
    sum.q = val.u[0] + val.u[1];
    *start = sum.u[0]; /* fits in 32 Bits */
}

static void get_timing( float *cpu, unsigned int start )
{
    rpcc val, sum, dif;
    float speed;

    val.q = __RPCC();
    sum.q = val.u[0] + val.u[1];

    dif.q = sum.u[0] - start;
    if ( dif.q < 0 ) {
	dif.q += 0xffffffff;
    }

    speed = cpu_speed();
    *cpu = (float) dif.u[0] / speed;
}



main(int argc, char *argv[])
{
    int	i,j;
    unsigned int start;
    float cpu;

    while (1)
    {

	start_timing( &start );

	for (i=0; i < 1000000; i++)
	{
	    j= i*i;
	}

	get_timing( &cpu, start );
	printf( "CPU-secs.: %8.6f\n", cpu );
    }
}

-- 
----------------------------------------------------------------------------
 Ulrich Kabatek, VMS Systems Manager      Email: kaba@isr.uni-stuttgart.de
 ISR, Uni Stuttgart                       Phone: 49-711-6856526
 Pfaffenwaldring 9, D-70550 Stuttgart     FAX:   49-711-6856371
============================================================================


