Humble script for creating the port's snapshots.
[AROS.git] / test / oop / test.c
blobecccebdb9e964e5bd5b743e42477681f80dd068a
1 /*
2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Demo of new OOP system
6 Lang: english
7 */
9 #include "oop.h"
10 #include "timerclass.h"
11 #include "protos.h"
12 #include "support.h"
13 #include "intern.h"
14 #include <stdio.h>
16 extern struct List ClassList;
19 #define NUM_ITERATIONS (10000000)
21 IPTR TestFunc(Class *cl, Object *o, Msg msg)
23 return (12345678);
27 int main(int argc, char **argv)
30 if (InitOOP())
32 Class *timercl;
34 printf("Object system initialized\n");
37 /* Initialize the timer class */
38 timercl = MakeTimerClass();
39 if (timercl)
42 struct Node *n;
43 Object *timer;
44 ULONG i;
46 printf("Class list:\n");
47 ForeachNode(&ClassList, n)
49 printf("%s\n", n->ln_Name);
51 printf("\n\n");
53 printf("Hash table:\n");
55 for (i = 0; i < timercl->HashTableSize; i ++)
57 struct Bucket *b;
58 printf("%ld: ", i);
60 for (b = timercl->HashTable[i]; b; b = b->Next)
62 printf("%s, %ld "
63 ,b->mClass->ClassNode.ln_Name
64 ,b->MethodID);
67 printf("\n");
72 /* Create a new instance */
73 timer = NewObject(NULL, TIMERCLASS, NULL);
74 if (timer)
76 ULONG i;
77 ULONG methodid = M_Timer_TestMethod;
79 printf("Timer object: %p\n", timer);
81 printf ("Doing ten billion calls to test method...\n");
84 /* Normal ivocation test */
85 printf ("Using normal invocation\n");
87 Timer_Start(timer);
89 for (i = 0; i < NUM_ITERATIONS; i ++)
91 Timer_TestMethod(timer);
94 Timer_Stop(timer);
95 printf("Time elapsed: ");
96 Timer_PrintElapsed(timer);
99 /* Fast ivocation test */
100 IPTR (*method)();
101 Class *cl;
103 printf ("\nUsing fast invocation\n");
105 GetMethod(timer, M_Timer_TestMethod, &method, &cl);
107 Timer_Start(timer);
109 for (i = 0; i < NUM_ITERATIONS; i ++)
111 method(cl, timer, (Msg)&methodid);
114 Timer_Stop(timer);
115 printf("Time elapsed: ");
116 Timer_PrintElapsed(timer);
118 printf("Method output: %ld\n", method(cl, timer, (Msg)&methodid));
120 /* Function test */
121 printf("\nTen billion calls to empty *function*\n");
122 Timer_Start(timer);
124 for (i = 0; i < NUM_ITERATIONS; i ++)
126 TestFunc(timercl, timer, (Msg)&methodid);
130 Timer_Stop(timer);
131 printf("Time elapsed: ");
132 Timer_PrintElapsed(timer);
136 /* Loop test */
137 printf("\nLooping ten billion times\n");
138 Timer_Start(timer);
140 for (i = 0; i < NUM_ITERATIONS; i ++)
142 ULONG retval;
143 retval = 12345678;
146 Timer_Stop(timer);
147 printf("Time elapsed: ");
148 Timer_PrintElapsed(timer);
150 printf("\n\nTestMethod output: %ld\n", Timer_TestMethod(timer));
152 /* Dispose object */
153 DisposeObject(timer);
156 FreeTimerClass(timercl);
158 CleanupOOP();
161 return (0);