[glib/g-property: 23/26] Test 'get' performance of GProperty



commit 7068a5585a55c18c0f91cefb91a5f9875c0ff90e
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Jul 8 17:34:14 2011 +0200

    Test 'get' performance of GProperty
    
    The 'set' performance tests that are being done necessarily involve an
    (expensive) call to g_object_notify() which obscures the performance
    difference between GProperty and native C calls.  Since property gets
    never involve g_object_notify() we add a new comparison based on getting
    properties rather than setting them so that we can ignore this cost.

 tests/gobject/performance.c |  111 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 105 insertions(+), 6 deletions(-)
---
diff --git a/tests/gobject/performance.c b/tests/gobject/performance.c
index 8971326..08bfc4e 100644
--- a/tests/gobject/performance.c
+++ b/tests/gobject/performance.c
@@ -449,6 +449,14 @@ paramspec_object_set_foo (ParamspecObject *object,
   g_object_notify_by_pspec (G_OBJECT (object), pspec_props[PROP_PSPEC_FOO]);
 }
 
+static int
+paramspec_object_get_foo (ParamspecObject *object)
+{
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (object, paramspec_object_get_type ()), 0);
+
+  return object->priv->foo;
+}
+
 static void
 paramspec_object_set_bar (ParamspecObject *object,
                           const char      *value)
@@ -474,6 +482,14 @@ paramspec_object_set_baz (ParamspecObject *object,
   g_object_notify_by_pspec (G_OBJECT (object), pspec_props[PROP_PSPEC_BAZ]);
 }
 
+static float
+paramspec_object_get_baz (ParamspecObject *object)
+{
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (object, paramspec_object_get_type ()), 0.0);
+
+  return object->priv->baz;
+}
+
 static void
 paramspec_object_set_property (GObject         *object,
                                guint            prop_id,
@@ -666,12 +682,32 @@ property_object_set_foo (PropertyObject *self, int value)
   g_property_set (((GProperty *) property_props[PROP_PROPERTY_FOO]), self, value);
 }
 
+static int
+property_object_get_foo (PropertyObject *self)
+{
+  gint value;
+
+  g_property_get (((GProperty *) property_props[PROP_PROPERTY_FOO]), self, &value);
+
+  return value;
+}
+
 static void
 property_object_set_baz (PropertyObject *self, float value)
 {
   g_property_set (((GProperty *) property_props[PROP_PROPERTY_BAZ]), self, value);
 }
 
+static float
+property_object_get_baz (PropertyObject *self)
+{
+  float value;
+
+  g_property_get (((GProperty *) property_props[PROP_PROPERTY_BAZ]), self, &value);
+
+  return value;
+}
+
 /*************************************************************
  * Test object construction performance
  *************************************************************/
@@ -792,8 +828,8 @@ test_property_init (PerformanceTest *test,
 }
 
 static void
-test_paramspec_direct_run (PerformanceTest *test,
-                           gpointer _data)
+test_paramspec_direct_set_run (PerformanceTest *test,
+                               gpointer _data)
 {
   struct PropertyTest *data = _data;
   int n_accesses, i;
@@ -810,6 +846,28 @@ test_paramspec_direct_run (PerformanceTest *test,
 }
 
 static void
+test_paramspec_direct_get_run (PerformanceTest *test,
+                               gpointer _data)
+{
+  struct PropertyTest *data = _data;
+  int n_accesses, i;
+
+  n_accesses = data->n_accesses;
+  for (i = 0; i < n_accesses; i++)
+    {
+      gint foo;
+      gfloat baz;
+
+      foo = paramspec_object_get_foo (data->object);
+      baz = paramspec_object_get_baz (data->object);
+
+      g_assert_cmpfloat (baz, ==, 0);
+      g_assert_cmpint (foo, ==, 50);
+    }
+}
+
+
+static void
 test_paramspec_object_run (PerformanceTest *test,
                            gpointer _data)
 {
@@ -830,8 +888,8 @@ test_paramspec_object_run (PerformanceTest *test,
 }
 
 static void
-test_property_direct_run (PerformanceTest *test,
-                          gpointer _data)
+test_property_direct_set_run (PerformanceTest *test,
+                              gpointer _data)
 {
   struct PropertyTest *data = _data;
   int n_accesses, i;
@@ -848,6 +906,27 @@ test_property_direct_run (PerformanceTest *test,
 }
 
 static void
+test_property_direct_get_run (PerformanceTest *test,
+                              gpointer _data)
+{
+  struct PropertyTest *data = _data;
+  int n_accesses, i;
+
+  n_accesses = data->n_accesses;
+  for (i = 0; i < n_accesses; i++)
+    {
+      gint foo;
+      gfloat baz;
+
+      foo = property_object_get_foo (data->object);
+      baz = property_object_get_baz (data->object);
+
+      g_assert_cmpfloat (baz, ==, 0);
+      g_assert_cmpint (foo, ==, 50);
+    }
+}
+
+static void
 test_property_object_run (PerformanceTest *test,
                           gpointer _data)
 {
@@ -1083,11 +1162,31 @@ static PerformanceTest tests[] = {
     test_construction_print_result
   },
   {
+    "gparamspec-direct-get",
+    paramspec_object_get_type,
+    test_property_setup,
+    test_property_init,
+    test_paramspec_direct_get_run,
+    test_property_finish,
+    test_property_teardown,
+    test_property_print_result
+  },
+  {
+    "gproperty-direct-get",
+    property_object_get_type,
+    test_property_setup,
+    test_property_init,
+    test_property_direct_get_run,
+    test_property_finish,
+    test_property_teardown,
+    test_property_print_result
+  },
+  {
     "gparamspec-direct-set",
     paramspec_object_get_type,
     test_property_setup,
     test_property_init,
-    test_paramspec_direct_run,
+    test_paramspec_direct_set_run,
     test_property_finish,
     test_property_teardown,
     test_property_print_result
@@ -1097,7 +1196,7 @@ static PerformanceTest tests[] = {
     property_object_get_type,
     test_property_setup,
     test_property_init,
-    test_property_direct_run,
+    test_property_direct_set_run,
     test_property_finish,
     test_property_teardown,
     test_property_print_result



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]