[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


clock

A program relative invocation of the system time.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <time.h>
clock_t clock(void);
Parameters:

None

Remarks:

This function is used to obtain values of type clock_t which may be used to calculate elapsed times during the execution of a program. To compute the elapsed time in seconds, divide the clock_t value by CLOCKS_PER_SEC, a macro defined in time.h.


WARNING!

The programmer should be aware that clock_t, defined in time.h, has a finite size that varies depending upon the target system.
Return:

The clock() function returns a clock_t type value representing the approximation of time since the system was started. There is no error value returned if an error occurs.

Example of clock() usage.:
#include <time.h>
#include <stdio.h>

int main()
{
	clock_t start, end;
	double  secs = 0;
	int stop = 0;

	fprintf( stderr, "Press enter to start");
	getchar();
	start = clock();

	while(stop != 'x')
	{
		fprintf( stderr, "Press enter to end");
		getchar();
		end = clock();
		secs =  (double)(end - start) /CLOCKS_PER_SEC;
		fprintf( stderr, "Elapsed seconds = %f \n", secs);
		fprintf( stderr,"Press enter to start again ");
		fprintf(stderr, "or enter x to end:  ");		 stop = getchar();
		start = clock();
	}

	printf("\n** Program has terminated ** \n");
	return 0;
}

Output:
Press enter to start <enter>
Press enter to end <enter>
Elapsed seconds = 1.200000 
Press enter to start again or enter x to end: <enter>
Press enter to end <enter>
Elapsed seconds = 1.033333 
Press enter to start again or enter x to end: <x enter>

** Program has terminated ** 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000