From 77a2d26ea2df321e2a964261f7f488dcd3c6f87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 13 Dec 2022 00:45:18 +0100 Subject: [PATCH 1/2] gobject/tests/performance: Add object notify performance tests --- gobject/tests/performance/performance.c | 191 ++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/gobject/tests/performance/performance.c b/gobject/tests/performance/performance.c index e2d0b1abd..7fff118d2 100644 --- a/gobject/tests/performance/performance.c +++ b/gobject/tests/performance/performance.c @@ -1,5 +1,6 @@ /* GObject - GLib Type, Object, Parameter and Signal Library * Copyright (C) 2009 Red Hat, Inc. + * Copyright (C) 2022 Canonical Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -906,6 +907,156 @@ test_emission_handled_teardown (PerformanceTest *test, g_free (data); } +/************************************************************* + * Test object notify performance (common code) + *************************************************************/ + +#define NUM_NOTIFY_PER_ROUND 10000 + +struct NotifyTest { + GObject *object; + unsigned n_checks; +}; + +static void +test_notify_run (PerformanceTest *test, + void *_data) +{ + struct NotifyTest *data = _data; + GObject *object = data->object; + + for (unsigned i = 0; i < data->n_checks; i++) + g_object_notify (object, "val1"); +} + +static void +test_notify_by_pspec_run (PerformanceTest *test, + void *_data) +{ + struct NotifyTest *data = _data; + GObject *object = data->object; + + for (unsigned i = 0; i < data->n_checks; i++) + g_object_notify_by_pspec (object, pspecs[PROP_VAL1]); +} + +/************************************************************* + * Test notify unhandled performance + *************************************************************/ + +static void * +test_notify_unhandled_setup (PerformanceTest *test) +{ + struct NotifyTest *data; + + data = g_new0 (struct NotifyTest, 1); + data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); + return data; +} + +static void +test_notify_unhandled_init (PerformanceTest *test, + void *_data, + double factor) +{ + struct NotifyTest *data = _data; + + data->n_checks = factor * NUM_NOTIFY_PER_ROUND; +} + +static void +test_notify_unhandled_finish (PerformanceTest *test, + void *data) +{ +} + +static void +test_notify_unhandled_print_result (PerformanceTest *test, + void *_data, + double time) +{ + struct NotifyTest *data = _data; + + g_print ("Notify (unhandled) per second: %.0f\n", + data->n_checks / time); +} + +static void +test_notify_unhandled_teardown (PerformanceTest *test, + void *_data) +{ + struct NotifyTest *data = _data; + + g_object_unref (data->object); + g_free (data); +} + +/************************************************************* + * Test notify handled performance + *************************************************************/ + +static void +test_notify_handled_handler (ComplexObject *obj, GParamSpec *pspec, void *data) +{ +} + +static void * +test_notify_handled_setup (PerformanceTest *test) +{ + struct NotifyTest *data; + + data = g_new0 (struct NotifyTest, 1); + data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); + + g_signal_connect (data->object, "notify::val1", + G_CALLBACK (test_notify_handled_handler), data); + g_signal_connect (data->object, "notify::val2", + G_CALLBACK (test_notify_handled_handler), data); + + return data; +} + +static void +test_notify_handled_init (PerformanceTest *test, + void *_data, + double factor) +{ + struct NotifyTest *data = _data; + + data->n_checks = factor * NUM_NOTIFY_PER_ROUND; +} + +static void +test_notify_handled_finish (PerformanceTest *test, + void *data) +{ +} + +static void +test_notify_handled_print_result (PerformanceTest *test, + void *_data, + double time) +{ + struct NotifyTest *data = _data; + + g_print ("Notify per second: %.0f\n", + data->n_checks / time); +} + +static void +test_notify_handled_teardown (PerformanceTest *test, + void *_data) +{ + struct NotifyTest *data = _data; + + g_assert_cmpuint ( + g_signal_handlers_disconnect_by_func (data->object, + test_notify_handled_handler, + data), ==, 2); + g_object_unref (data->object); + g_free (data); +} + /************************************************************* * Test object refcount performance *************************************************************/ @@ -1163,6 +1314,46 @@ static PerformanceTest tests[] = { test_emission_handled_teardown, test_emission_handled_print_result }, + { + "notify-unhandled", + complex_object_get_type, + test_notify_unhandled_setup, + test_notify_unhandled_init, + test_notify_run, + test_notify_unhandled_finish, + test_notify_unhandled_teardown, + test_notify_unhandled_print_result + }, + { + "notify-by-pspec-unhandled", + complex_object_get_type, + test_notify_unhandled_setup, + test_notify_unhandled_init, + test_notify_by_pspec_run, + test_notify_unhandled_finish, + test_notify_unhandled_teardown, + test_notify_unhandled_print_result + }, + { + "notify-handled", + complex_object_get_type, + test_notify_handled_setup, + test_notify_handled_init, + test_notify_run, + test_notify_handled_finish, + test_notify_handled_teardown, + test_notify_handled_print_result + }, + { + "notify-by-pspec-handled", + complex_object_get_type, + test_notify_handled_setup, + test_notify_handled_init, + test_notify_by_pspec_run, + test_notify_handled_finish, + test_notify_handled_teardown, + test_notify_handled_print_result + }, { "refcount", NULL, From c6f252108cc3902e6d3212644a903752ba675dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 13 Dec 2022 00:55:03 +0100 Subject: [PATCH 2/2] gobject/tests/performance: Add object get/set performance tests --- gobject/tests/performance/performance.c | 161 ++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/gobject/tests/performance/performance.c b/gobject/tests/performance/performance.c index 7fff118d2..e8ad3915e 100644 --- a/gobject/tests/performance/performance.c +++ b/gobject/tests/performance/performance.c @@ -1057,6 +1057,147 @@ test_notify_handled_teardown (PerformanceTest *test, g_free (data); } +/************************************************************* + * Test object set performance + *************************************************************/ + +#define NUM_SET_PER_ROUND 10000 + +struct SetTest { + GObject *object; + unsigned n_checks; +}; + +static void +test_set_run (PerformanceTest *test, + void *_data) +{ + struct SetTest *data = _data; + GObject *object = data->object; + + for (unsigned i = 0; i < data->n_checks; i++) + g_object_set (object, "val1", i, NULL); +} + +static void * +test_set_setup (PerformanceTest *test) +{ + struct SetTest *data; + + data = g_new0 (struct SetTest, 1); + data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); + + return data; +} + +static void +test_set_init (PerformanceTest *test, + void *_data, + double factor) +{ + struct SetTest *data = _data; + + data->n_checks = factor * NUM_SET_PER_ROUND; +} + +static void +test_set_finish (PerformanceTest *test, + void *data) +{ +} + +static void +test_set_print_result (PerformanceTest *test, + void *_data, + double time) +{ + struct SetTest *data = _data; + + g_print ("Property set per second: %.0f\n", + data->n_checks / time); +} + +static void +test_set_teardown (PerformanceTest *test, + void *_data) +{ + struct SetTest *data = _data; + + g_object_unref (data->object); + g_free (data); +} + +/************************************************************* + * Test object get performance + *************************************************************/ + +#define NUM_GET_PER_ROUND 10000 + +struct GetTest { + GObject *object; + unsigned n_checks; +}; + +static void +test_get_run (PerformanceTest *test, + void *_data) +{ + struct GetTest *data = _data; + GObject *object = data->object; + int val; + + for (unsigned i = 0; i < data->n_checks; i++) + g_object_get (object, "val1", &val, NULL); +} + +static void * +test_get_setup (PerformanceTest *test) +{ + struct GetTest *data; + + data = g_new0 (struct GetTest, 1); + data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); + + return data; +} + +static void +test_get_init (PerformanceTest *test, + void *_data, + double factor) +{ + struct GetTest *data = _data; + + data->n_checks = factor * NUM_GET_PER_ROUND; +} + +static void +test_get_finish (PerformanceTest *test, + void *data) +{ +} + +static void +test_get_print_result (PerformanceTest *test, + void *_data, + double time) +{ + struct GetTest *data = _data; + + g_print ("Property get per second: %.0f\n", + data->n_checks / time); +} + +static void +test_get_teardown (PerformanceTest *test, + gpointer _data) +{ + struct GetTest *data = _data; + + g_object_unref (data->object); + g_free (data); +} + /************************************************************* * Test object refcount performance *************************************************************/ @@ -1354,6 +1495,26 @@ static PerformanceTest tests[] = { test_notify_handled_teardown, test_notify_handled_print_result }, + { + "property-set", + complex_object_get_type, + test_set_setup, + test_set_init, + test_set_run, + test_set_finish, + test_set_teardown, + test_set_print_result + }, + { + "property-get", + complex_object_get_type, + test_get_setup, + test_get_init, + test_get_run, + test_get_finish, + test_get_teardown, + test_get_print_result + }, { "refcount", NULL,