8 This is a trick to make the timer.device's timeval struct not clash with the
9 sys/time.h's one. I'm using gettymeofday 'cause I'm lazy and don't wanna
10 bother with timer.device myself :)
12 On AROS this is handled automatically (go AROS!)
14 # define timeval timeval_aos
17 #include <exec/tasks.h>
18 #include <proto/exec.h>
19 #include <clib/alib_protos.h>
20 #include <proto/dos.h>
23 /* The trick is over... */
27 #ifndef __typedef_STACKIPTR
28 /* Normal AmigaOS environments don't have this defined */
29 typedef ULONG STACKIPTR
;
32 #ifndef AROS_STACKSIZE
33 # define AROS_STACKSIZE 4096
36 /* Give some prettier names to the standard signals */
37 #define SIGF_STOP SIGBREAKF_CTRL_C
38 #define SIGF_HELLO SIGBREAKF_CTRL_D
39 #define SIGF_BYE SIGBREAKF_CTRL_E
40 #define SIGF_START SIGBREAKF_CTRL_F
42 static unsigned long counter
= 0;
43 static struct Task
*task1
, *task2
;
45 static struct timeval start_tv
, end_tv
;
51 if (Wait(SIGF_HELLO
| SIGF_STOP
) == SIGF_HELLO
)
52 Signal(task2
, SIGF_HELLO
);
67 Signal(task1
, SIGF_HELLO
);
68 if (Wait(SIGF_HELLO
| SIGF_STOP
) == SIGF_HELLO
)
72 Signal(task1
, SIGF_BYE
);
78 int __nocommandline
= 1;
81 define this to non-zero if you want the benchmark to end automatically
82 when it realizes that there's no need to continue.
84 Beware that it can introduce some overhead (although very little).
86 #define SELF_TIMED_TEST 0
92 task1
= CreateTask("Task 1", 0, Task1Entry
, AROS_STACKSIZE
);
93 task2
= CreateTask("Task 2", 0, Task2Entry
, AROS_STACKSIZE
);
97 "The test is starting.\n"
99 "Press CTRL-C to stop the test and get the results.\n"
100 "Wait a few seconds before doing so, in order to get a more accurate result\n\n"
104 gettimeofday(&start_tv
, NULL
);
106 Signal(task2
, SIGF_START
);
118 ratio
= (double)i
/counter
;
119 if ((ratio
- oldratio
) <= .000000001) break;
131 gettimeofday(&end_tv
, NULL
);
133 Signal(task1
, SIGF_STOP
);
134 Signal(task2
, SIGF_STOP
);
136 elapsed
= ((double)(((end_tv
.tv_sec
* 1000000) + end_tv
.tv_usec
) - ((start_tv
.tv_sec
* 1000000) + start_tv
.tv_usec
)))/1000000.;
140 "Elapsed time: %f seconds\n"
141 "Number of context switches: %ld\n"
142 "Signal roundtrip time: %.8f\n"
143 "Context switch time: <= %.8f seconds\n",
146 elapsed
/ (double)counter
,
147 elapsed
/ (double)(counter
* 2)