©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c1/timetst.c

Go to the documentation of this file.
00001 /*
00002     Testing timestart and timestop
00003     Sec. 1.7.2
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
00019 
00020 */
00021 #include "defs.h"
00022 #include <sys/times.h>
00023 #include <sys/time.h>
00024 
00025 /*[time_test]*/
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 }

Generated on Fri Apr 23 10:56:54 2004 for AUP2 Example Source by doxygen 1.3.1