00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022 #include <sys/times.h>
00023 #include <sys/time.h>
00024
00025
00026 #define REPS 1000000
00027 #define TV_SUBTRACT(t2, t1)\
00028 (double)(t2).tv_sec + (t2).tv_usec / 1000000.0 -\
00029 ((double)(t1).tv_sec + (t1).tv_usec / 1000000.0)
00030
00031 int main(void)
00032 {
00033 int i;
00034 char msg[100];
00035 clock_t c1, c2;
00036 struct timeval tv1, tv2;
00037
00038 snprintf(msg, sizeof(msg), "%d getpids", REPS);
00039 ec_neg1( c1 = clock() )
00040 gettimeofday(&tv1, NULL);
00041 timestart();
00042 for (i = 0; i < REPS; i++)
00043 (void)getpid();
00044 (void)sleep(2);
00045 timestop(msg);
00046 gettimeofday(&tv2, NULL);
00047 ec_neg1( c2 = clock() )
00048 printf("clock(): %.2f\n", (double)(c2 - c1) / CLOCKS_PER_SEC);
00049 printf("gettimeofday(): %.2f\n", TV_SUBTRACT(tv2, tv1));
00050 exit(EXIT_SUCCESS);
00051
00052 EC_CLEANUP_BGN
00053 exit(EXIT_FAILURE);
00054 EC_CLEANUP_END
00055 }