26 #include "hrt_stopwatch.h"
27 #include "hrt_gstopwatch.h"
37 const unsigned long loop = 1000000000L;
39 static volatile unsigned long dummy;
40 for (i = 0; i < loop; i++)
45 main(
int argc,
const char* argv[])
47 printf(
"--> main()\n");
49 printf(
"init stopwatches...\n");
51 assert(hrt_gsw_top() == -1);
54 assert(hrt_sw_top(&sw) == -1);
56 printf(
"marking global time...\n");
57 int g0 = hrt_gsw_pushmark();
60 printf(
"marking time...\n");
61 int t0 = hrt_sw_pushmark(&sw);
64 printf(
"marking time...\n");
65 int t1 = hrt_sw_pushmark(&sw);
68 printf(
"marking time...\n");
69 int t2 = hrt_sw_pushmark(&sw);
72 printf(
"marking global time...\n");
73 int g2 = hrt_gsw_pushmark();
75 assert(hrt_gsw_top() == 1);
76 assert(hrt_sw_top(&sw) == 2);
78 printf(
"\namount of times:\n");
79 double rt0 = hrt_sw_rtmicros(&sw, t1, t0);
80 double rt1 = hrt_sw_rtmicros(&sw, t2, t1);
81 double rt2 = hrt_sw_rtmicros(&sw, t2, t0);
82 double grt2 = hrt_gsw_rtmicros(g2, g0);
83 printf(
"[t0..t1] real = %.3f us\n", rt0);
84 printf(
"[t1..t2] real = %.3f us\n", rt1);
85 printf(
"[t0..t2] real = %.3f us\n", rt2);
86 printf(
"[g0..g2] real = %.3f us\n", grt2);
87 double ct0 = hrt_sw_ctmicros(&sw, t1, t0);
88 double ct1 = hrt_sw_ctmicros(&sw, t2, t1);
89 double ct2 = hrt_sw_ctmicros(&sw, t2, t0);
90 double gct2 = hrt_gsw_ctmicros(g2, g0);
91 printf(
"[t0..t1] cpu = %.3f us\n", ct0);
92 printf(
"[t1..t2] cpu = %.3f us\n", ct1);
93 printf(
"[t0..t2] cpu = %.3f us\n", ct2);
94 printf(
"[g0..g2] cpu = %.3f us\n", gct2);
96 printf(
"\npopping timemarks...\n");
98 assert(hrt_gsw_top() == 0);
100 assert(hrt_gsw_top() == -1);
102 assert(hrt_sw_top(&sw) == 1);
104 assert(hrt_sw_top(&sw) == 0);
106 assert(hrt_sw_top(&sw) == -1);
108 printf(
"closing stopwatches...\n");
112 printf(
"\n<-- main()\n");