1 #include <glib-object.h>
8 GObjectClass parent_class
;
17 guint signals
[LAST_SIGNAL
];
19 GType
my_obj_get_type (void);
21 G_DEFINE_TYPE (MyObj
, my_obj
, G_TYPE_OBJECT
)
24 my_obj_init (MyObj
*o
)
29 my_obj_class_init (MyObjClass
*class)
32 g_signal_new ("signal1",
33 G_TYPE_FROM_CLASS (class),
35 0, NULL
, NULL
, NULL
, G_TYPE_NONE
, 0);
37 g_signal_new ("signal2",
38 G_TYPE_FROM_CLASS (class),
40 0, NULL
, NULL
, NULL
, G_TYPE_NONE
, 0);
48 #define HANDLERS 500000
51 test_connect_many (void)
57 o
= g_object_new (my_obj_get_type (), NULL
);
59 g_test_timer_start ();
61 for (i
= 0; i
< HANDLERS
; i
++)
62 g_signal_connect (o
, "signal1", G_CALLBACK (nop
), NULL
);
64 time_elapsed
= g_test_timer_elapsed ();
68 g_test_minimized_result (time_elapsed
, "connected %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
72 test_disconnect_many_ordered (void)
75 gulong handlers
[HANDLERS
];
79 o
= g_object_new (my_obj_get_type (), NULL
);
81 for (i
= 0; i
< HANDLERS
; i
++)
82 handlers
[i
] = g_signal_connect (o
, "signal1", G_CALLBACK (nop
), NULL
);
84 g_test_timer_start ();
86 for (i
= 0; i
< HANDLERS
; i
++)
87 g_signal_handler_disconnect (o
, handlers
[i
]);
89 time_elapsed
= g_test_timer_elapsed ();
93 g_test_minimized_result (time_elapsed
, "disconnected %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
97 test_disconnect_many_inverse (void)
100 gulong handlers
[HANDLERS
];
101 gdouble time_elapsed
;
104 o
= g_object_new (my_obj_get_type (), NULL
);
106 for (i
= 0; i
< HANDLERS
; i
++)
107 handlers
[i
] = g_signal_connect (o
, "signal1", G_CALLBACK (nop
), NULL
);
109 g_test_timer_start ();
111 for (i
= HANDLERS
- 1; i
>= 0; i
--)
112 g_signal_handler_disconnect (o
, handlers
[i
]);
114 time_elapsed
= g_test_timer_elapsed ();
118 g_test_minimized_result (time_elapsed
, "disconnected %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
122 test_disconnect_many_random (void)
125 gulong handlers
[HANDLERS
];
127 gdouble time_elapsed
;
130 o
= g_object_new (my_obj_get_type (), NULL
);
132 for (i
= 0; i
< HANDLERS
; i
++)
133 handlers
[i
] = g_signal_connect (o
, "signal1", G_CALLBACK (nop
), NULL
);
135 for (i
= 0; i
< HANDLERS
; i
++)
137 j
= g_test_rand_int_range (0, HANDLERS
);
139 handlers
[i
] = handlers
[j
];
143 g_test_timer_start ();
145 for (i
= 0; i
< HANDLERS
; i
++)
146 g_signal_handler_disconnect (o
, handlers
[i
]);
148 time_elapsed
= g_test_timer_elapsed ();
152 g_test_minimized_result (time_elapsed
, "disconnected %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
156 test_disconnect_2_signals (void)
159 gulong handlers
[HANDLERS
];
161 gdouble time_elapsed
;
164 o
= g_object_new (my_obj_get_type (), NULL
);
166 for (i
= 0; i
< HANDLERS
; i
++)
169 handlers
[i
] = g_signal_connect (o
, "signal1", G_CALLBACK (nop
), NULL
);
171 handlers
[i
] = g_signal_connect (o
, "signal2", G_CALLBACK (nop
), NULL
);
174 for (i
= 0; i
< HANDLERS
; i
++)
176 j
= g_test_rand_int_range (0, HANDLERS
);
178 handlers
[i
] = handlers
[j
];
182 g_test_timer_start ();
184 for (i
= 0; i
< HANDLERS
; i
++)
185 g_signal_handler_disconnect (o
, handlers
[i
]);
187 time_elapsed
= g_test_timer_elapsed ();
191 g_test_minimized_result (time_elapsed
, "disconnected %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
195 test_disconnect_2_objects (void)
198 gulong handlers
[HANDLERS
];
199 MyObj
*objects
[HANDLERS
];
201 gdouble time_elapsed
;
204 o1
= g_object_new (my_obj_get_type (), NULL
);
205 o2
= g_object_new (my_obj_get_type (), NULL
);
207 for (i
= 0; i
< HANDLERS
; i
++)
211 handlers
[i
] = g_signal_connect (o1
, "signal1", G_CALLBACK (nop
), NULL
);
216 handlers
[i
] = g_signal_connect (o2
, "signal1", G_CALLBACK (nop
), NULL
);
221 for (i
= 0; i
< HANDLERS
; i
++)
223 j
= g_test_rand_int_range (0, HANDLERS
);
225 handlers
[i
] = handlers
[j
];
228 objects
[i
] = objects
[j
];
232 g_test_timer_start ();
234 for (i
= 0; i
< HANDLERS
; i
++)
235 g_signal_handler_disconnect (objects
[i
], handlers
[i
]);
237 time_elapsed
= g_test_timer_elapsed ();
242 g_test_minimized_result (time_elapsed
, "disconnected %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
246 test_block_many (void)
249 gulong handlers
[HANDLERS
];
251 gdouble time_elapsed
;
254 o
= g_object_new (my_obj_get_type (), NULL
);
256 for (i
= 0; i
< HANDLERS
; i
++)
257 handlers
[i
] = g_signal_connect (o
, "signal1", G_CALLBACK (nop
), NULL
);
259 for (i
= 0; i
< HANDLERS
; i
++)
261 j
= g_test_rand_int_range (0, HANDLERS
);
263 handlers
[i
] = handlers
[j
];
267 g_test_timer_start ();
269 for (i
= 0; i
< HANDLERS
; i
++)
270 g_signal_handler_block (o
, handlers
[i
]);
272 for (i
= HANDLERS
- 1; i
>= 0; i
--)
273 g_signal_handler_unblock (o
, handlers
[i
]);
275 time_elapsed
= g_test_timer_elapsed ();
279 g_test_minimized_result (time_elapsed
, "blocked and unblocked %u handlers in %6.3f seconds", HANDLERS
, time_elapsed
);
283 main (int argc
, char *argv
[])
285 g_test_init (&argc
, &argv
, NULL
);
289 g_test_add_func ("/signal/handler/connect-many", test_connect_many
);
290 g_test_add_func ("/signal/handler/disconnect-many-ordered", test_disconnect_many_ordered
);
291 g_test_add_func ("/signal/handler/disconnect-many-inverse", test_disconnect_many_inverse
);
292 g_test_add_func ("/signal/handler/disconnect-many-random", test_disconnect_many_random
);
293 g_test_add_func ("/signal/handler/disconnect-2-signals", test_disconnect_2_signals
);
294 g_test_add_func ("/signal/handler/disconnect-2-objects", test_disconnect_2_objects
);
295 g_test_add_func ("/signal/handler/block-many", test_block_many
);
298 return g_test_run ();