1 |
#include <sys/time.h> |
2 |
#include <stdio.h> |
3 |
|
4 |
void timeratio_() { |
5 |
/* |
6 |
three invocations produce |
7 |
the ratio of the timedifference of |
8 |
the 3rd vs. the 2nd invocation over |
9 |
the difference of the 2nd vs. the 1st invocation |
10 |
*/ |
11 |
static short stage=0; |
12 |
#define tvCount 3 |
13 |
static struct timeval tv_a[tvCount]; |
14 |
double deltaThis, deltaPrevious; |
15 |
if (stage<tvCount) |
16 |
gettimeofday(&(tv_a[stage]),0); |
17 |
printf("OAD: TIMING: stamp %u: %lu.%06lu\n", |
18 |
stage, |
19 |
tv_a[stage].tv_sec, |
20 |
tv_a[stage].tv_usec); |
21 |
if (stage>0) { |
22 |
printf("OAD: TIMING: delta stamps %u-%u: %lu.%06lu\n", |
23 |
stage, |
24 |
stage-1, |
25 |
(tv_a[stage].tv_usec<tv_a[stage-1].tv_usec)?tv_a[stage].tv_sec-tv_a[stage-1].tv_sec-1:tv_a[stage].tv_sec-tv_a[stage-1].tv_sec, |
26 |
(tv_a[stage].tv_usec<tv_a[stage-1].tv_usec)?1000000-(tv_a[stage-1].tv_usec-tv_a[stage].tv_usec):tv_a[stage].tv_usec-tv_a[stage-1].tv_usec); |
27 |
} |
28 |
if (stage>1) { |
29 |
printf("OAD: TIMING: delta stamps %u-%u: %lu.%06lu\n", |
30 |
stage, |
31 |
0, |
32 |
(tv_a[stage].tv_usec<tv_a[0].tv_usec)?tv_a[stage].tv_sec-tv_a[0].tv_sec-1:tv_a[stage].tv_sec-tv_a[0].tv_sec, |
33 |
(tv_a[stage].tv_usec<tv_a[0].tv_usec)?1000000-(tv_a[0].tv_usec-tv_a[stage].tv_usec):tv_a[stage].tv_usec-tv_a[0].tv_usec); |
34 |
} |
35 |
if (stage==tvCount-1 && stage>1) { |
36 |
deltaThis=(tv_a[stage].tv_usec<tv_a[stage-1].tv_usec)?tv_a[stage].tv_sec-tv_a[stage-1].tv_sec-1:tv_a[stage].tv_sec-tv_a[stage-1].tv_sec; |
37 |
deltaThis*=1.0e6; |
38 |
deltaThis+=(tv_a[stage].tv_usec<tv_a[stage-1].tv_usec)?1000000-(tv_a[stage-1].tv_usec-tv_a[stage].tv_usec):tv_a[stage].tv_usec-tv_a[stage-1].tv_usec; |
39 |
deltaPrevious=(tv_a[stage-1].tv_usec<tv_a[stage-2].tv_usec)?tv_a[stage-1].tv_sec-tv_a[stage-2].tv_sec-1:tv_a[stage-1].tv_sec-tv_a[stage-2].tv_sec; |
40 |
deltaPrevious*=1.0e6; |
41 |
deltaPrevious+=(tv_a[stage-1].tv_usec<tv_a[stage-2].tv_usec)?1000000-(tv_a[stage-2].tv_usec-tv_a[stage-1].tv_usec):tv_a[stage-1].tv_usec-tv_a[stage-2].tv_usec; |
42 |
printf("OAD: TIMING: ratio stamps (%u-%u)/(%u-%u): %e/%e=%e\n", |
43 |
stage, |
44 |
stage-1, |
45 |
stage-1, |
46 |
stage-2, |
47 |
deltaThis, |
48 |
deltaPrevious, |
49 |
deltaThis/deltaPrevious); |
50 |
stage=0; |
51 |
} |
52 |
else |
53 |
stage++; |
54 |
} |