Drop trailing semi-colon from G_DEFINE_ macro
[glib.git] / tests / gobject / performance.c
bloba592b7d853c975664099db6895d209b459998c3d
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2009 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #include <math.h>
19 #include <string.h>
20 #include <glib-object.h>
21 #include "testcommon.h"
23 #define WARM_UP_N_RUNS 50
24 #define ESTIMATE_ROUND_TIME_N_RUNS 5
25 #define DEFAULT_TEST_TIME 15 /* seconds */
26 /* The time we want each round to take, in seconds, this should
27 * be large enough compared to the timer resolution, but small
28 * enought that the risk of any random slowness will miss the
29 * running window */
30 #define TARGET_ROUND_TIME 0.008
32 static gboolean verbose = FALSE;
33 static int test_length = DEFAULT_TEST_TIME;
35 static GOptionEntry cmd_entries[] = {
36 {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
37 "Print extra information", NULL},
38 {"seconds", 's', 0, G_OPTION_ARG_INT, &test_length,
39 "Time to run each test in seconds", NULL},
40 {NULL}
43 typedef struct _PerformanceTest PerformanceTest;
44 struct _PerformanceTest {
45 const char *name;
46 gpointer extra_data;
48 gpointer (*setup) (PerformanceTest *test);
49 void (*init) (PerformanceTest *test,
50 gpointer data,
51 double factor);
52 void (*run) (PerformanceTest *test,
53 gpointer data);
54 void (*finish) (PerformanceTest *test,
55 gpointer data);
56 void (*teardown) (PerformanceTest *test,
57 gpointer data);
58 void (*print_result) (PerformanceTest *test,
59 gpointer data,
60 double time);
63 static void
64 run_test (PerformanceTest *test)
66 gpointer data = NULL;
67 guint64 i, num_rounds;
68 double elapsed, min_elapsed, max_elapsed, avg_elapsed, factor;
69 GTimer *timer;
71 g_print ("Running test %s\n", test->name);
73 /* Set up test */
74 timer = g_timer_new ();
75 data = test->setup (test);
77 if (verbose)
78 g_print ("Warming up\n");
80 g_timer_start (timer);
82 /* Warm up the test by doing a few runs */
83 for (i = 0; i < WARM_UP_N_RUNS; i++)
85 test->init (test, data, 1.0);
86 test->run (test, data);
87 test->finish (test, data);
90 g_timer_stop (timer);
91 elapsed = g_timer_elapsed (timer, NULL);
93 if (verbose)
95 g_print ("Warm up time: %.2f secs\n", elapsed);
96 g_print ("Estimating round time\n");
99 /* Estimate time for one run by doing a few test rounds */
100 min_elapsed = 0;
101 for (i = 0; i < ESTIMATE_ROUND_TIME_N_RUNS; i++)
103 test->init (test, data, 1.0);
104 g_timer_start (timer);
105 test->run (test, data);
106 g_timer_stop (timer);
107 test->finish (test, data);
109 elapsed = g_timer_elapsed (timer, NULL);
110 if (i == 0)
111 min_elapsed = elapsed;
112 else
113 min_elapsed = MIN (min_elapsed, elapsed);
116 factor = TARGET_ROUND_TIME / min_elapsed;
118 if (verbose)
119 g_print ("Uncorrected round time: %.4f msecs, correction factor %.2f\n", 1000*min_elapsed, factor);
121 /* Calculate number of rounds needed */
122 num_rounds = (test_length / TARGET_ROUND_TIME) + 1;
124 if (verbose)
125 g_print ("Running %"G_GINT64_MODIFIER"d rounds\n", num_rounds);
127 /* Run the test */
128 for (i = 0; i < num_rounds; i++)
130 test->init (test, data, factor);
131 g_timer_start (timer);
132 test->run (test, data);
133 g_timer_stop (timer);
134 test->finish (test, data);
135 elapsed = g_timer_elapsed (timer, NULL);
137 if (i == 0)
138 max_elapsed = min_elapsed = avg_elapsed = elapsed;
139 else
141 min_elapsed = MIN (min_elapsed, elapsed);
142 max_elapsed = MAX (max_elapsed, elapsed);
143 avg_elapsed += elapsed;
147 avg_elapsed = avg_elapsed / num_rounds;
149 if (verbose)
151 g_print ("Minimum corrected round time: %.2f msecs\n", min_elapsed * 1000);
152 g_print ("Maximum corrected round time: %.2f msecs\n", max_elapsed * 1000);
153 g_print ("Average corrected round time: %.2f msecs\n", avg_elapsed * 1000);
155 /* Print the results */
156 test->print_result (test, data, min_elapsed);
158 /* Tear down */
159 test->teardown (test, data);
160 g_timer_destroy (timer);
163 /*************************************************************
164 * Simple object is a very simple small GObject subclass
165 * with no properties, no signals, implementing no interfaces
166 *************************************************************/
168 static GType simple_object_get_type (void);
169 #define SIMPLE_TYPE_OBJECT (simple_object_get_type ())
170 typedef struct _SimpleObject SimpleObject;
171 typedef struct _SimpleObjectClass SimpleObjectClass;
173 struct _SimpleObject
175 GObject parent_instance;
176 int val;
179 struct _SimpleObjectClass
181 GObjectClass parent_class;
184 G_DEFINE_TYPE (SimpleObject, simple_object, G_TYPE_OBJECT)
186 static void
187 simple_object_finalize (GObject *object)
189 G_OBJECT_CLASS (simple_object_parent_class)->finalize (object);
192 static void
193 simple_object_class_init (SimpleObjectClass *class)
195 GObjectClass *object_class = G_OBJECT_CLASS (class);
197 object_class->finalize = simple_object_finalize;
200 static void
201 simple_object_init (SimpleObject *simple_object)
203 simple_object->val = 42;
206 typedef struct _TestIfaceClass TestIfaceClass;
207 typedef struct _TestIfaceClass TestIface1Class;
208 typedef struct _TestIfaceClass TestIface2Class;
209 typedef struct _TestIfaceClass TestIface3Class;
210 typedef struct _TestIfaceClass TestIface4Class;
211 typedef struct _TestIfaceClass TestIface5Class;
212 typedef struct _TestIface TestIface;
214 struct _TestIfaceClass
216 GTypeInterface base_iface;
217 void (*method) (TestIface *obj);
220 static GType test_iface1_get_type (void);
221 static GType test_iface2_get_type (void);
222 static GType test_iface3_get_type (void);
223 static GType test_iface4_get_type (void);
224 static GType test_iface5_get_type (void);
226 #define TEST_TYPE_IFACE1 (test_iface1_get_type ())
227 #define TEST_TYPE_IFACE2 (test_iface2_get_type ())
228 #define TEST_TYPE_IFACE3 (test_iface3_get_type ())
229 #define TEST_TYPE_IFACE4 (test_iface4_get_type ())
230 #define TEST_TYPE_IFACE5 (test_iface5_get_type ())
232 static DEFINE_IFACE (TestIface1, test_iface1, NULL, NULL)
233 static DEFINE_IFACE (TestIface2, test_iface2, NULL, NULL)
234 static DEFINE_IFACE (TestIface3, test_iface3, NULL, NULL)
235 static DEFINE_IFACE (TestIface4, test_iface4, NULL, NULL)
236 static DEFINE_IFACE (TestIface5, test_iface5, NULL, NULL)
238 /*************************************************************
239 * Complex object is a GObject subclass with a properties,
240 * construct properties, signals and implementing an interface.
241 *************************************************************/
243 static GType complex_object_get_type (void);
244 #define COMPLEX_TYPE_OBJECT (complex_object_get_type ())
245 typedef struct _ComplexObject ComplexObject;
246 typedef struct _ComplexObjectClass ComplexObjectClass;
248 struct _ComplexObject
250 GObject parent_instance;
251 int val1;
252 int val2;
255 struct _ComplexObjectClass
257 GObjectClass parent_class;
259 void (*signal) (ComplexObject *obj);
260 void (*signal_empty) (ComplexObject *obj);
263 static void complex_test_iface_init (gpointer g_iface,
264 gpointer iface_data);
266 G_DEFINE_TYPE_EXTENDED (ComplexObject, complex_object,
267 G_TYPE_OBJECT, 0,
268 G_IMPLEMENT_INTERFACE (TEST_TYPE_IFACE1, complex_test_iface_init)
269 G_IMPLEMENT_INTERFACE (TEST_TYPE_IFACE2, complex_test_iface_init)
270 G_IMPLEMENT_INTERFACE (TEST_TYPE_IFACE3, complex_test_iface_init)
271 G_IMPLEMENT_INTERFACE (TEST_TYPE_IFACE4, complex_test_iface_init)
272 G_IMPLEMENT_INTERFACE (TEST_TYPE_IFACE5, complex_test_iface_init))
274 #define COMPLEX_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), COMPLEX_TYPE_OBJECT, ComplexObject))
276 enum {
277 PROP_0,
278 PROP_VAL1,
279 PROP_VAL2
282 enum {
283 COMPLEX_SIGNAL,
284 COMPLEX_SIGNAL_EMPTY,
285 COMPLEX_SIGNAL_GENERIC,
286 COMPLEX_SIGNAL_GENERIC_EMPTY,
287 COMPLEX_SIGNAL_ARGS,
288 COMPLEX_LAST_SIGNAL
291 static guint complex_signals[COMPLEX_LAST_SIGNAL] = { 0 };
293 static void
294 complex_object_finalize (GObject *object)
296 G_OBJECT_CLASS (complex_object_parent_class)->finalize (object);
299 static void
300 complex_object_set_property (GObject *object,
301 guint prop_id,
302 const GValue *value,
303 GParamSpec *pspec)
305 ComplexObject *complex = COMPLEX_OBJECT (object);
307 switch (prop_id)
309 case PROP_VAL1:
310 complex->val1 = g_value_get_int (value);
311 break;
312 case PROP_VAL2:
313 complex->val2 = g_value_get_int (value);
314 break;
315 default:
316 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
317 break;
321 static void
322 complex_object_get_property (GObject *object,
323 guint prop_id,
324 GValue *value,
325 GParamSpec *pspec)
327 ComplexObject *complex = COMPLEX_OBJECT (object);
329 switch (prop_id)
331 case PROP_VAL1:
332 g_value_set_int (value, complex->val1);
333 break;
334 case PROP_VAL2:
335 g_value_set_int (value, complex->val2);
336 break;
337 default:
338 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 break;
343 static void
344 complex_object_real_signal (ComplexObject *obj)
348 static void
349 complex_object_class_init (ComplexObjectClass *class)
351 GObjectClass *object_class = G_OBJECT_CLASS (class);
353 object_class->finalize = complex_object_finalize;
354 object_class->set_property = complex_object_set_property;
355 object_class->get_property = complex_object_get_property;
357 class->signal = complex_object_real_signal;
359 complex_signals[COMPLEX_SIGNAL] =
360 g_signal_new ("signal",
361 G_TYPE_FROM_CLASS (object_class),
362 G_SIGNAL_RUN_FIRST,
363 G_STRUCT_OFFSET (ComplexObjectClass, signal),
364 NULL, NULL,
365 g_cclosure_marshal_VOID__VOID,
366 G_TYPE_NONE, 0);
368 complex_signals[COMPLEX_SIGNAL_EMPTY] =
369 g_signal_new ("signal-empty",
370 G_TYPE_FROM_CLASS (object_class),
371 G_SIGNAL_RUN_FIRST,
372 G_STRUCT_OFFSET (ComplexObjectClass, signal_empty),
373 NULL, NULL,
374 g_cclosure_marshal_VOID__VOID,
375 G_TYPE_NONE, 0);
377 complex_signals[COMPLEX_SIGNAL_GENERIC] =
378 g_signal_new ("signal-generic",
379 G_TYPE_FROM_CLASS (object_class),
380 G_SIGNAL_RUN_FIRST,
381 G_STRUCT_OFFSET (ComplexObjectClass, signal),
382 NULL, NULL,
383 NULL,
384 G_TYPE_NONE, 0);
385 complex_signals[COMPLEX_SIGNAL_GENERIC_EMPTY] =
386 g_signal_new ("signal-generic-empty",
387 G_TYPE_FROM_CLASS (object_class),
388 G_SIGNAL_RUN_FIRST,
389 G_STRUCT_OFFSET (ComplexObjectClass, signal_empty),
390 NULL, NULL,
391 NULL,
392 G_TYPE_NONE, 0);
394 complex_signals[COMPLEX_SIGNAL_ARGS] =
395 g_signal_new ("signal-args",
396 G_TYPE_FROM_CLASS (object_class),
397 G_SIGNAL_RUN_FIRST,
398 G_STRUCT_OFFSET (ComplexObjectClass, signal),
399 NULL, NULL,
400 g_cclosure_marshal_VOID__UINT_POINTER,
401 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_POINTER);
403 g_object_class_install_property (object_class,
404 PROP_VAL1,
405 g_param_spec_int ("val1",
406 "val1",
407 "val1",
409 G_MAXINT,
411 G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
412 g_object_class_install_property (object_class,
413 PROP_VAL2,
414 g_param_spec_int ("val2",
415 "val2",
416 "val2",
418 G_MAXINT,
420 G_PARAM_READWRITE));
425 static void
426 complex_object_iface_method (TestIface *obj)
428 ComplexObject *complex = COMPLEX_OBJECT (obj);
429 complex->val1++;
432 static void
433 complex_test_iface_init (gpointer g_iface,
434 gpointer iface_data)
436 TestIfaceClass *iface = g_iface;
437 iface->method = complex_object_iface_method;
440 static void
441 complex_object_init (ComplexObject *complex_object)
443 complex_object->val2 = 43;
446 /*************************************************************
447 * Test object construction performance
448 *************************************************************/
450 #define NUM_OBJECT_TO_CONSTRUCT 10000
452 struct ConstructionTest {
453 GObject **objects;
454 int n_objects;
455 GType type;
458 static gpointer
459 test_construction_setup (PerformanceTest *test)
461 struct ConstructionTest *data;
463 data = g_new0 (struct ConstructionTest, 1);
464 data->type = ((GType (*)(void))test->extra_data)();
466 return data;
469 static void
470 test_construction_init (PerformanceTest *test,
471 gpointer _data,
472 double count_factor)
474 struct ConstructionTest *data = _data;
475 int n;
477 n = NUM_OBJECT_TO_CONSTRUCT * count_factor;
478 if (data->n_objects != n)
480 data->n_objects = n;
481 data->objects = g_new (GObject *, n);
485 static void
486 test_construction_run (PerformanceTest *test,
487 gpointer _data)
489 struct ConstructionTest *data = _data;
490 GObject **objects = data->objects;
491 GType type = data->type;
492 int i, n_objects;
494 n_objects = data->n_objects;
495 for (i = 0; i < n_objects; i++)
496 objects[i] = g_object_new (type, NULL);
499 static void
500 test_construction_finish (PerformanceTest *test,
501 gpointer _data)
503 struct ConstructionTest *data = _data;
504 int i;
506 for (i = 0; i < data->n_objects; i++)
507 g_object_unref (data->objects[i]);
510 static void
511 test_construction_teardown (PerformanceTest *test,
512 gpointer _data)
514 struct ConstructionTest *data = _data;
515 g_free (data->objects);
516 g_free (data);
519 static void
520 test_construction_print_result (PerformanceTest *test,
521 gpointer _data,
522 double time)
524 struct ConstructionTest *data = _data;
526 g_print ("Millions of constructed objects per second: %.3f\n",
527 data->n_objects / (time * 1000000));
530 /*************************************************************
531 * Test runtime type check performance
532 *************************************************************/
534 #define NUM_KILO_CHECKS_PER_ROUND 50
536 struct TypeCheckTest {
537 GObject *object;
538 int n_checks;
541 static gpointer
542 test_type_check_setup (PerformanceTest *test)
544 struct TypeCheckTest *data;
546 data = g_new0 (struct TypeCheckTest, 1);
547 data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
549 return data;
552 static void
553 test_type_check_init (PerformanceTest *test,
554 gpointer _data,
555 double factor)
557 struct TypeCheckTest *data = _data;
559 data->n_checks = factor * NUM_KILO_CHECKS_PER_ROUND;
563 /* Work around g_type_check_instance_is_a being marked "pure",
564 and thus only called once for the loop. */
565 gboolean (*my_type_check_instance_is_a) (GTypeInstance *type_instance,
566 GType iface_type) = &g_type_check_instance_is_a;
568 static void
569 test_type_check_run (PerformanceTest *test,
570 gpointer _data)
572 struct TypeCheckTest *data = _data;
573 volatile GObject *object = data->object;
574 volatile GType type, types[5];
575 int i, j;
577 types[0] = test_iface1_get_type ();
578 types[1] = test_iface2_get_type ();
579 types[2] = test_iface3_get_type ();
580 types[3] = test_iface4_get_type ();
581 types[4] = test_iface5_get_type ();
583 for (i = 0; i < data->n_checks; i++)
585 type = types[i%5];
586 for (j = 0; j < 1000; j++)
588 my_type_check_instance_is_a ((GTypeInstance *)object,
589 type);
594 static void
595 test_type_check_finish (PerformanceTest *test,
596 gpointer data)
600 static void
601 test_type_check_print_result (PerformanceTest *test,
602 gpointer _data,
603 double time)
605 struct TypeCheckTest *data = _data;
606 g_print ("Million type checks per second: %.2f\n",
607 data->n_checks / (1000*time));
610 static void
611 test_type_check_teardown (PerformanceTest *test,
612 gpointer _data)
614 struct TypeCheckTest *data = _data;
616 g_object_unref (data->object);
617 g_free (data);
620 /*************************************************************
621 * Test signal emissions performance (common code)
622 *************************************************************/
624 #define NUM_EMISSIONS_PER_ROUND 10000
626 struct EmissionTest {
627 GObject *object;
628 int n_checks;
629 int signal_id;
632 static void
633 test_emission_run (PerformanceTest *test,
634 gpointer _data)
636 struct EmissionTest *data = _data;
637 GObject *object = data->object;
638 int i;
640 for (i = 0; i < data->n_checks; i++)
641 g_signal_emit (object, data->signal_id, 0);
644 static void
645 test_emission_run_args (PerformanceTest *test,
646 gpointer _data)
648 struct EmissionTest *data = _data;
649 GObject *object = data->object;
650 int i;
652 for (i = 0; i < data->n_checks; i++)
653 g_signal_emit (object, data->signal_id, 0, 0, NULL);
656 /*************************************************************
657 * Test signal unhandled emissions performance
658 *************************************************************/
660 static gpointer
661 test_emission_unhandled_setup (PerformanceTest *test)
663 struct EmissionTest *data;
665 data = g_new0 (struct EmissionTest, 1);
666 data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
667 data->signal_id = complex_signals[GPOINTER_TO_INT (test->extra_data)];
668 return data;
671 static void
672 test_emission_unhandled_init (PerformanceTest *test,
673 gpointer _data,
674 double factor)
676 struct EmissionTest *data = _data;
678 data->n_checks = factor * NUM_EMISSIONS_PER_ROUND;
681 static void
682 test_emission_unhandled_finish (PerformanceTest *test,
683 gpointer data)
687 static void
688 test_emission_unhandled_print_result (PerformanceTest *test,
689 gpointer _data,
690 double time)
692 struct EmissionTest *data = _data;
694 g_print ("Emissions per second: %.0f\n",
695 data->n_checks / time);
698 static void
699 test_emission_unhandled_teardown (PerformanceTest *test,
700 gpointer _data)
702 struct EmissionTest *data = _data;
704 g_object_unref (data->object);
705 g_free (data);
708 /*************************************************************
709 * Test signal handled emissions performance
710 *************************************************************/
712 static void
713 test_emission_handled_handler (ComplexObject *obj, gpointer data)
717 static gpointer
718 test_emission_handled_setup (PerformanceTest *test)
720 struct EmissionTest *data;
722 data = g_new0 (struct EmissionTest, 1);
723 data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
724 data->signal_id = complex_signals[GPOINTER_TO_INT (test->extra_data)];
725 g_signal_connect (data->object, "signal",
726 G_CALLBACK (test_emission_handled_handler),
727 NULL);
728 g_signal_connect (data->object, "signal-empty",
729 G_CALLBACK (test_emission_handled_handler),
730 NULL);
731 g_signal_connect (data->object, "signal-generic",
732 G_CALLBACK (test_emission_handled_handler),
733 NULL);
734 g_signal_connect (data->object, "signal-generic-empty",
735 G_CALLBACK (test_emission_handled_handler),
736 NULL);
737 g_signal_connect (data->object, "signal-args",
738 G_CALLBACK (test_emission_handled_handler),
739 NULL);
741 return data;
744 static void
745 test_emission_handled_init (PerformanceTest *test,
746 gpointer _data,
747 double factor)
749 struct EmissionTest *data = _data;
751 data->n_checks = factor * NUM_EMISSIONS_PER_ROUND;
754 static void
755 test_emission_handled_finish (PerformanceTest *test,
756 gpointer data)
760 static void
761 test_emission_handled_print_result (PerformanceTest *test,
762 gpointer _data,
763 double time)
765 struct EmissionTest *data = _data;
767 g_print ("Emissions per second: %.0f\n",
768 data->n_checks / time);
771 static void
772 test_emission_handled_teardown (PerformanceTest *test,
773 gpointer _data)
775 struct EmissionTest *data = _data;
777 g_object_unref (data->object);
778 g_free (data);
781 /*************************************************************
782 * Test object refcount performance
783 *************************************************************/
785 #define NUM_KILO_REFS_PER_ROUND 100000
787 struct RefcountTest {
788 GObject *object;
789 int n_checks;
792 static gpointer
793 test_refcount_setup (PerformanceTest *test)
795 struct RefcountTest *data;
797 data = g_new0 (struct RefcountTest, 1);
798 data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL);
800 return data;
803 static void
804 test_refcount_init (PerformanceTest *test,
805 gpointer _data,
806 double factor)
808 struct RefcountTest *data = _data;
810 data->n_checks = factor * NUM_KILO_REFS_PER_ROUND;
813 static void
814 test_refcount_run (PerformanceTest *test,
815 gpointer _data)
817 struct RefcountTest *data = _data;
818 GObject *object = data->object;
819 int i;
821 for (i = 0; i < data->n_checks; i++)
823 g_object_ref (object);
824 g_object_ref (object);
825 g_object_ref (object);
826 g_object_unref (object);
827 g_object_unref (object);
829 g_object_ref (object);
830 g_object_ref (object);
831 g_object_unref (object);
832 g_object_unref (object);
833 g_object_unref (object);
837 static void
838 test_refcount_finish (PerformanceTest *test,
839 gpointer _data)
843 static void
844 test_refcount_print_result (PerformanceTest *test,
845 gpointer _data,
846 double time)
848 struct RefcountTest *data = _data;
849 g_print ("Million refs+unref per second: %.2f\n",
850 data->n_checks * 5 / (time * 1000000 ));
853 static void
854 test_refcount_teardown (PerformanceTest *test,
855 gpointer _data)
857 struct RefcountTest *data = _data;
859 g_object_unref (data->object);
860 g_free (data);
863 /*************************************************************
864 * Main test code
865 *************************************************************/
867 static PerformanceTest tests[] = {
869 "simple-construction",
870 simple_object_get_type,
871 test_construction_setup,
872 test_construction_init,
873 test_construction_run,
874 test_construction_finish,
875 test_construction_teardown,
876 test_construction_print_result
879 "complex-construction",
880 complex_object_get_type,
881 test_construction_setup,
882 test_construction_init,
883 test_construction_run,
884 test_construction_finish,
885 test_construction_teardown,
886 test_construction_print_result
889 "type-check",
890 NULL,
891 test_type_check_setup,
892 test_type_check_init,
893 test_type_check_run,
894 test_type_check_finish,
895 test_type_check_teardown,
896 test_type_check_print_result
899 "emit-unhandled",
900 GINT_TO_POINTER (COMPLEX_SIGNAL),
901 test_emission_unhandled_setup,
902 test_emission_unhandled_init,
903 test_emission_run,
904 test_emission_unhandled_finish,
905 test_emission_unhandled_teardown,
906 test_emission_unhandled_print_result
909 "emit-unhandled-empty",
910 GINT_TO_POINTER (COMPLEX_SIGNAL_EMPTY),
911 test_emission_unhandled_setup,
912 test_emission_unhandled_init,
913 test_emission_run,
914 test_emission_unhandled_finish,
915 test_emission_unhandled_teardown,
916 test_emission_unhandled_print_result
919 "emit-unhandled-generic",
920 GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC),
921 test_emission_unhandled_setup,
922 test_emission_unhandled_init,
923 test_emission_run,
924 test_emission_unhandled_finish,
925 test_emission_unhandled_teardown,
926 test_emission_unhandled_print_result
929 "emit-unhandled-generic-empty",
930 GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC_EMPTY),
931 test_emission_unhandled_setup,
932 test_emission_unhandled_init,
933 test_emission_run,
934 test_emission_unhandled_finish,
935 test_emission_unhandled_teardown,
936 test_emission_unhandled_print_result
939 "emit-unhandled-args",
940 GINT_TO_POINTER (COMPLEX_SIGNAL_ARGS),
941 test_emission_unhandled_setup,
942 test_emission_unhandled_init,
943 test_emission_run_args,
944 test_emission_unhandled_finish,
945 test_emission_unhandled_teardown,
946 test_emission_unhandled_print_result
949 "emit-handled",
950 GINT_TO_POINTER (COMPLEX_SIGNAL),
951 test_emission_handled_setup,
952 test_emission_handled_init,
953 test_emission_run,
954 test_emission_handled_finish,
955 test_emission_handled_teardown,
956 test_emission_handled_print_result
959 "emit-handled-empty",
960 GINT_TO_POINTER (COMPLEX_SIGNAL_EMPTY),
961 test_emission_handled_setup,
962 test_emission_handled_init,
963 test_emission_run,
964 test_emission_handled_finish,
965 test_emission_handled_teardown,
966 test_emission_handled_print_result
969 "emit-handled-generic",
970 GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC),
971 test_emission_handled_setup,
972 test_emission_handled_init,
973 test_emission_run,
974 test_emission_handled_finish,
975 test_emission_handled_teardown,
976 test_emission_handled_print_result
979 "emit-handled-generic-empty",
980 GINT_TO_POINTER (COMPLEX_SIGNAL_GENERIC_EMPTY),
981 test_emission_handled_setup,
982 test_emission_handled_init,
983 test_emission_run,
984 test_emission_handled_finish,
985 test_emission_handled_teardown,
986 test_emission_handled_print_result
989 "emit-handled-args",
990 GINT_TO_POINTER (COMPLEX_SIGNAL_ARGS),
991 test_emission_handled_setup,
992 test_emission_handled_init,
993 test_emission_run_args,
994 test_emission_handled_finish,
995 test_emission_handled_teardown,
996 test_emission_handled_print_result
999 "refcount",
1000 NULL,
1001 test_refcount_setup,
1002 test_refcount_init,
1003 test_refcount_run,
1004 test_refcount_finish,
1005 test_refcount_teardown,
1006 test_refcount_print_result
1010 static PerformanceTest *
1011 find_test (const char *name)
1013 int i;
1014 for (i = 0; i < G_N_ELEMENTS (tests); i++)
1016 if (strcmp (tests[i].name, name) == 0)
1017 return &tests[i];
1019 return NULL;
1022 main (int argc,
1023 char *argv[])
1025 PerformanceTest *test;
1026 GOptionContext *context;
1027 GError *error = NULL;
1028 int i;
1030 context = g_option_context_new ("GObject performance tests");
1031 g_option_context_add_main_entries (context, cmd_entries, NULL);
1032 if (!g_option_context_parse (context, &argc, &argv, &error))
1034 g_printerr ("%s: %s\n", argv[0], error->message);
1035 return 1;
1038 if (argc > 1)
1040 for (i = 1; i < argc; i++)
1042 test = find_test (argv[i]);
1043 if (test)
1044 run_test (test);
1047 else
1049 for (i = 0; i < G_N_ELEMENTS (tests); i++)
1050 run_test (&tests[i]);
1053 return 0;