~ubuntu-branches/ubuntu/natty/orbit2/natty

« back to all changes in this revision

Viewing changes to test/test-performance.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Waters
  • Date: 2002-03-25 17:24:03 UTC
  • Revision ID: james.westby@ubuntu.com-20020325172403-8lexv63608acfqgt
Tags: upstream-2.3.107
ImportĀ upstreamĀ versionĀ 2.3.107

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
 
 
5
#include <orbit/orbit.h>
 
6
 
 
7
#include "test1.h"
 
8
 
 
9
static CORBA_ORB  orb;
 
10
static GTimer    *timer;
 
11
static double     bogomark = 0.0;
 
12
static double     elapsed_time;
 
13
 
 
14
static void
 
15
test_copy (void)
 
16
{
 
17
        int i, j;
 
18
#define ELEMS (sizeof (tc) / sizeof (tc[0]))
 
19
        CORBA_TypeCode tc[] = {
 
20
                TC_CORBA_octet,
 
21
                TC_CORBA_sequence_CORBA_octet,
 
22
                TC_CORBA_double,
 
23
                TC_CORBA_string,
 
24
                TC_CORBA_sequence_CORBA_string,
 
25
                TC_GIOP_TargetAddress           
 
26
        };
 
27
        gpointer data [ELEMS];
 
28
        const char *test_string = "This is a sample string, for dupping";
 
29
 
 
30
        fprintf (stderr, "Testing copy...\n");
 
31
 
 
32
        for (i = 0; i < ELEMS; i++) {
 
33
                data [i] = ORBit_dynany_new_default (tc [i]);
 
34
 
 
35
                g_timer_reset (timer);
 
36
                for (j = 0; j < 1000; j++) {
 
37
                        gpointer foo = ORBit_copy_value (data [i], tc [i]);
 
38
                        CORBA_free (foo);
 
39
                }
 
40
                elapsed_time = g_timer_elapsed (timer, NULL);
 
41
                bogomark += elapsed_time;
 
42
                fprintf (stderr, " copy %20s : %g(ms)\n",
 
43
                        tc[i]->repo_id == NULL ? "(null)" : tc[i]->repo_id,
 
44
                        elapsed_time);
 
45
        }
 
46
 
 
47
        fprintf (stderr, "Testing strdup ...\n");
 
48
        
 
49
        g_timer_reset (timer);
 
50
 
 
51
        for (i = 0; i < 1000; i++) {
 
52
                char *str = CORBA_string_dup (test_string);
 
53
                CORBA_free (str);
 
54
        }
 
55
        elapsed_time = g_timer_elapsed (timer, NULL);
 
56
        bogomark += elapsed_time;
 
57
        fprintf (stderr, " strdup : %g(ms)\n", elapsed_time);
 
58
}
 
59
 
 
60
static PortableServer_POA
 
61
create_mult_id_poa (CORBA_Environment *ev)
 
62
{
 
63
        PortableServer_POA  rootpoa;
 
64
        PortableServer_POA  retval;
 
65
        CORBA_PolicyList   *policies;
 
66
 
 
67
        rootpoa = (PortableServer_POA)
 
68
                CORBA_ORB_resolve_initial_references (orb, "RootPOA", ev);
 
69
        g_assert (ev->_major == CORBA_NO_EXCEPTION);
 
70
 
 
71
        policies           = CORBA_PolicyList__alloc ();
 
72
        policies->_maximum = 1;
 
73
        policies->_length  = 1;
 
74
        policies->_buffer  = CORBA_PolicyList_allocbuf (1);
 
75
        CORBA_sequence_set_release (policies, CORBA_TRUE);
 
76
 
 
77
        policies->_buffer[0] = (CORBA_Policy)
 
78
                                        PortableServer_POA_create_id_uniqueness_policy (
 
79
                                                        rootpoa,
 
80
                                                        PortableServer_MULTIPLE_ID,
 
81
                                                        ev);
 
82
        g_assert (ev->_major == CORBA_NO_EXCEPTION);
 
83
 
 
84
        retval = PortableServer_POA_create_POA (rootpoa, "Multiple Id POA",
 
85
                                                NULL, policies, ev);
 
86
        g_assert (ev->_major == CORBA_NO_EXCEPTION);
 
87
 
 
88
        CORBA_Policy_destroy (policies->_buffer[0], ev);
 
89
        CORBA_free (policies);
 
90
 
 
91
        g_assert (ev->_major == CORBA_NO_EXCEPTION);
 
92
 
 
93
        CORBA_Object_release ((CORBA_Object) rootpoa, ev);
 
94
 
 
95
        g_assert (ev->_major == CORBA_NO_EXCEPTION);
 
96
 
 
97
        return retval;
 
98
}
 
99
 
 
100
PortableServer_ServantBase__epv base_epv = { NULL, NULL, NULL };
 
101
POA_Test__epv                   test_epv = { NULL, NULL };
 
102
POA_Test__vepv                  test_vepv = { &base_epv, &test_epv };
 
103
POA_Test                        test_servant = { NULL, &test_vepv };
 
104
 
 
105
static void
 
106
test_activation (void)
 
107
{
 
108
        CORBA_Environment   env;
 
109
        PortableServer_POA  poa;
 
110
        GSList             *objids = NULL, *l;
 
111
        int                 i;
 
112
 
 
113
        fprintf (stderr, "Testing object activation...\n");
 
114
 
 
115
        CORBA_exception_init (&env);
 
116
 
 
117
        POA_Test__init (&test_servant, &env);
 
118
 
 
119
        poa = create_mult_id_poa (&env);
 
120
 
 
121
        g_assert (env._major == CORBA_NO_EXCEPTION);
 
122
 
 
123
        g_timer_reset (timer);
 
124
 
 
125
        for (i = 0; i < 1000; i++) {
 
126
                PortableServer_ObjectId *objid;
 
127
 
 
128
                objid = PortableServer_POA_activate_object (poa, &test_servant, &env);
 
129
                g_assert (env._major == CORBA_NO_EXCEPTION);
 
130
 
 
131
                objids = g_slist_append (objids, objid);
 
132
        }
 
133
 
 
134
        elapsed_time = g_timer_elapsed (timer, NULL);
 
135
        bogomark += elapsed_time;
 
136
        fprintf (stderr, " activation : %g(ms)\n", elapsed_time);
 
137
 
 
138
        g_timer_reset (timer);
 
139
 
 
140
        for (l = objids; l; l = l->next) {
 
141
                PortableServer_POA_deactivate_object (poa, l->data, &env);
 
142
                g_assert (env._major == CORBA_NO_EXCEPTION);
 
143
        }
 
144
 
 
145
        elapsed_time = g_timer_elapsed (timer, NULL);
 
146
        bogomark += elapsed_time;
 
147
        fprintf (stderr, " de-activation : %g(ms)\n", elapsed_time);
 
148
        
 
149
        for (l = objids; l; l = l->next)
 
150
                CORBA_free (l->data);
 
151
        g_slist_free (objids);
 
152
 
 
153
        POA_Test__fini (&test_servant, &env);
 
154
 
 
155
        CORBA_Object_release ((CORBA_Object) poa, &env);
 
156
        g_assert (env._major == CORBA_NO_EXCEPTION);
 
157
 
 
158
        CORBA_exception_free (&env);
 
159
}
 
160
 
 
161
int
 
162
main (int argc, char *argv[])
 
163
{
 
164
        CORBA_Environment ev;
 
165
 
 
166
        free (malloc (8));
 
167
 
 
168
        CORBA_exception_init (&ev);
 
169
 
 
170
        timer = g_timer_new ();
 
171
        g_timer_start (timer);
 
172
 
 
173
        g_timer_reset (timer);
 
174
        orb = CORBA_ORB_init (&argc, argv, "orbit-local-orb", &ev);
 
175
        g_assert (ev._major == CORBA_NO_EXCEPTION);
 
176
        fprintf (stderr, "ORB: init took %g(ms)\n",
 
177
                 (elapsed_time = g_timer_elapsed (timer, NULL)) * 1000.0);
 
178
        bogomark += elapsed_time;
 
179
 
 
180
        test_copy ();
 
181
 
 
182
        test_activation ();
 
183
 
 
184
        g_timer_reset (timer);
 
185
        CORBA_ORB_destroy (orb, &ev);
 
186
        g_assert (ev._major == CORBA_NO_EXCEPTION);
 
187
        fprintf (stderr, "ORB: destroy took %g(ms)\n",
 
188
                 (elapsed_time = g_timer_elapsed (timer, NULL)) * 1000.0);
 
189
        bogomark += elapsed_time;
 
190
        g_timer_reset (timer);
 
191
 
 
192
        CORBA_Object_release ((CORBA_Object) orb, &ev);
 
193
        g_assert (ev._major == CORBA_NO_EXCEPTION);
 
194
 
 
195
        g_timer_destroy (timer);
 
196
 
 
197
        fprintf (stderr, "Overall bogomark %g\n", 1000.0 / bogomark);
 
198
 
 
199
        return 0;
 
200
}