nicer output
[tridge/junkcode.git] / usleep.c
1 #include <unistd.h>
2 #include <sys/time.h>
3 #include <time.h>
4
5 static struct timeval tp1,tp2;
6
7 static void start_timer()
8 {
9         gettimeofday(&tp1,NULL);
10 }
11
12 static double end_timer()
13 {
14         gettimeofday(&tp2,NULL);
15         return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) - 
16                 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
17 }
18
19 int main(int argc, char *argv[])
20 {
21         unsigned long t;
22
23         t = atoi(argv[1]);
24
25         while (1) {
26                 start_timer();
27                 usleep(t);
28                 printf("%f milliseconds\n", end_timer() * 1000);
29         }
30         return 0;
31 }