Spelling fix.
[AROS.git] / test / timeport.c
blobd9e621a75f8f4d12aa28a79b53cf5823ab0a1ef4
1 #include <exec/types.h>
2 #include <exec/ports.h>
3 #include <dos/dosextens.h>
4 #include <dos/dostags.h>
5 #include <aros/libcall.h>
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <stdio.h>
9 #include <sys/time.h>
10 #include <time.h>
12 #define NUM_MESSAGES (1000000)
14 AROS_UFH3(void, taskentry,
15 AROS_UFHA(STRPTR, argPtr, A0),
16 AROS_UFHA(ULONG, argSize, D0),
17 AROS_UFHA(struct ExecBase *, SysBase, A6)) {
18 AROS_USERFUNC_INIT
20 int i;
21 struct MsgPort *port = (struct MsgPort *) FindTask(NULL)->tc_UserData;
23 for (i = 0; i < NUM_MESSAGES; i++) {
24 WaitPort(port);
25 ReplyMsg(GetMsg(port));
28 AROS_USERFUNC_EXIT
31 AROS_UFH3(void, intentry,
32 AROS_UFHA(APTR, data, A1),
33 AROS_UFHA(APTR, code, A5),
34 AROS_UFHA(struct ExecBase *, SysBase, A6)) {
35 AROS_USERFUNC_INIT
37 struct MsgPort *port = (struct MsgPort *) data;
39 WaitPort(port);
40 ReplyMsg(GetMsg(port));
42 AROS_USERFUNC_EXIT
45 AROS_UFH4(void, fastentry,
46 AROS_UFHA(APTR, data, A1),
47 AROS_UFHA(APTR, code, A5),
48 AROS_UFHA(struct Message *, msg, D0),
49 AROS_UFHA(struct ExecBase *, SysBase, A6)) {
50 AROS_USERFUNC_INIT
52 ReplyMsg(msg);
54 AROS_USERFUNC_EXIT
57 AROS_UFH2(void, callentry,
58 AROS_UFHA(struct MsgPort *, port, D0),
59 AROS_UFHA(struct ExecBase *, SysBase, A6)) {
60 AROS_USERFUNC_INIT
62 WaitPort(port);
63 ReplyMsg(GetMsg(port));
65 AROS_USERFUNC_EXIT
68 int main(int argc, char **argv) {
69 struct MsgPort *port, *reply;
70 struct Message *msg;
71 struct Process *proc;
72 int i;
73 struct timeval start, end;
74 struct Interrupt *intr;
76 printf("testing with %d messages\n", NUM_MESSAGES);
78 port = CreateMsgPort();
79 reply = CreateMsgPort();
81 msg = AllocVec(sizeof(struct Message), MEMF_PUBLIC | MEMF_CLEAR);
82 msg->mn_Length = sizeof(struct Message);
83 msg->mn_ReplyPort = reply;
85 proc = CreateNewProcTags(NP_Entry, (IPTR) taskentry,
86 NP_Name, "timeport task",
87 NP_UserData, (IPTR) port,
88 TAG_DONE);
90 port->mp_Flags = PA_SIGNAL;
91 port->mp_SigTask = (struct Task *) proc;
93 gettimeofday(&start, NULL);
95 for (i = 0; i < NUM_MESSAGES; i++) {
96 PutMsg(port, msg);
97 WaitPort(reply);
98 GetMsg(reply);
101 gettimeofday(&end, NULL);
103 while (end.tv_usec < start.tv_usec) {
104 end.tv_sec--;
105 end.tv_usec += 1000000;
108 printf("PA_SIGNAL: %ld.%lds\n",(long)( end.tv_sec - start.tv_sec), (long)(end.tv_usec - start.tv_usec) / 1000);
110 intr = AllocVec(sizeof(struct Interrupt), MEMF_PUBLIC | MEMF_CLEAR);
111 intr->is_Code = intentry;
112 intr->is_Data = port;
114 port->mp_Flags = PA_SOFTINT;
115 port->mp_SoftInt = intr;
117 gettimeofday(&start, NULL);
119 for (i = 0; i < NUM_MESSAGES; i++) {
120 PutMsg(port, msg);
121 WaitPort(reply);
122 GetMsg(reply);
125 gettimeofday(&end, NULL);
127 while (end.tv_usec < start.tv_usec) {
128 end.tv_sec--;
129 end.tv_usec += 1000000;
132 printf("PA_SOFTINT: %ld.%lds\n", (long)(end.tv_sec - start.tv_sec), (long)(end.tv_usec - start.tv_usec) / 1000);
134 port->mp_Flags = PA_CALL;
135 port->mp_SigTask = callentry;
137 gettimeofday(&start, NULL);
139 for (i = 0; i < NUM_MESSAGES; i++) {
140 PutMsg(port, msg);
141 WaitPort(reply);
142 GetMsg(reply);
145 gettimeofday(&end, NULL);
147 while (end.tv_usec < start.tv_usec) {
148 end.tv_sec--;
149 end.tv_usec += 1000000;
152 printf("PA_CALL: %ld.%lds\n", (long)(end.tv_sec - start.tv_sec), (long)(end.tv_usec - start.tv_usec) / 1000);
154 intr->is_Code = fastentry;
156 port->mp_Flags = PA_FASTCALL;
157 port->mp_SoftInt = intr;
159 gettimeofday(&start, NULL);
161 for (i = 0; i < NUM_MESSAGES; i++) {
162 PutMsg(port, msg);
163 WaitPort(reply);
164 GetMsg(reply);
167 gettimeofday(&end, NULL);
169 while (end.tv_usec < start.tv_usec) {
170 end.tv_sec--;
171 end.tv_usec += 1000000;
174 printf("PA_FASTCALL: %ld.%lds\n", (long)(end.tv_sec - start.tv_sec), (long)(end.tv_usec - start.tv_usec) / 1000);
176 FreeVec(intr);
178 FreeVec(msg);
180 DeleteMsgPort(reply);
181 DeleteMsgPort(port);
183 return 0;