2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
11 This is a trick to make the timer.device's timeval struct not clash with the
12 sys/time.h's one. I'm using gettymeofday 'cause I'm lazy and don't wanna
13 bother with timer.device myself :)
15 On AROS this is handled automatically (go AROS!)
17 # define timeval timeval_aos
20 #include <exec/tasks.h>
21 #include <proto/exec.h>
22 #include <clib/alib_protos.h>
23 #include <proto/dos.h>
26 /* The trick is over... */
30 #ifndef __typedef_STACKIPTR
31 /* Normal AmigaOS environments don't have this defined */
32 typedef ULONG STACKIPTR
;
35 #ifndef AROS_STACKSIZE
36 # define AROS_STACKSIZE 4096
39 /* Give some prettier names to the standard signals */
40 #define SIGF_STOP SIGBREAKF_CTRL_C
41 #define SIGF_HELLO SIGBREAKF_CTRL_D
42 #define SIGF_BYE SIGBREAKF_CTRL_E
43 #define SIGF_START SIGBREAKF_CTRL_F
45 static unsigned long counter
= 0;
46 static struct Task
*task1
, *task2
;
48 static struct timeval start_tv
, end_tv
;
54 if (Wait(SIGF_HELLO
| SIGF_STOP
) == SIGF_HELLO
)
55 Signal(task2
, SIGF_HELLO
);
70 Signal(task1
, SIGF_HELLO
);
71 if (Wait(SIGF_HELLO
| SIGF_STOP
) == SIGF_HELLO
)
75 Signal(task1
, SIGF_BYE
);
81 int __nocommandline
= 1;
84 define this to non-zero if you want the benchmark to end automatically
85 when it realizes that there's no need to continue.
87 Beware that it can introduce some overhead (although very little).
89 #define SELF_TIMED_TEST 0
95 task1
= CreateTask("Task 1", 0, Task1Entry
, AROS_STACKSIZE
);
96 task2
= CreateTask("Task 2", 0, Task2Entry
, AROS_STACKSIZE
);
100 "The test is starting.\n"
102 "Press CTRL-C to stop the test and get the results.\n"
103 "Wait a few seconds before doing so, in order to get a more accurate result\n\n"
107 gettimeofday(&start_tv
, NULL
);
109 Signal(task2
, SIGF_START
);
121 ratio
= (double)i
/counter
;
122 if ((ratio
- oldratio
) <= .000000001) break;
134 gettimeofday(&end_tv
, NULL
);
136 Signal(task1
, SIGF_STOP
);
137 Signal(task2
, SIGF_STOP
);
139 elapsed
= ((double)(((end_tv
.tv_sec
* 1000000) + end_tv
.tv_usec
) - ((start_tv
.tv_sec
* 1000000) + start_tv
.tv_usec
)))/1000000.;
143 "Elapsed time: %f seconds\n"
144 "Number of context switches: %ld\n"
145 "Signal roundtrip time: %.8f\n"
146 "Context switch time: <= %.8f seconds\n",
149 elapsed
/ (double)counter
,
150 elapsed
/ (double)(counter
* 2)