4 * Time-stamp: <26.10.2004 11:57:13h liekweg>
6 * File name: ir/ana2/timing.c
7 * Purpose: generic timing routines
10 * Created: Mon 18 Oct 2004
12 * Copyright: (c) 1999-2004 Universität Karlsruhe
13 * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 Timing stuff. Not really part of ana2, but where else should it go.
31 timeval_subtract (struct timeval *x, struct timeval *y)
33 /* Perform the carry for the later subtraction by updating Y. */
34 if (x->tv_usec < y->tv_usec) {
35 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
36 y->tv_usec -= 1000000 * nsec;
40 if (x->tv_usec - y->tv_usec > 1000000) {
41 int nsec = (x->tv_usec - y->tv_usec) / 1000000;
42 y->tv_usec += 1000000 * nsec;
46 return ((x->tv_sec - y->tv_sec) * 1000000 + (x->tv_usec - y->tv_usec));
56 timing_t *t = (timing_t*) malloc (sizeof (timing_t));
58 t->start = (struct timeval*) malloc (sizeof (struct timeval));
59 t->end = (struct timeval*) malloc (sizeof (struct timeval));
61 gettimeofday (t->start, NULL);
67 end_timing (timing_t *t)
71 gettimeofday (t->end, NULL);
73 time = timeval_subtract (t->end, t->start);
75 memset (t->start, 0x0, sizeof (struct timeval));
78 memset (t->end, 0x0, sizeof (struct timeval));
81 memset (t, 0x00, sizeof (timing_t));
90 Revision 1.1 2004/10/29 18:55:52 liekweg
91 (mostly) generic timimg