summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2009-09-26 20:03:21 +0200
committerEdward Hervey <bilboed@bilboed.com>2009-10-01 18:11:30 +0200
commit4b93d0e001079b3141b62864cfb4857281720200 (patch)
tree8067d4439a19c12e1e48cca5b8bf01213f3c3e23
parentb1963a92561098dfee58c2d92d954ef5bfced625 (diff)
tests/performance-threaded: Add instance and simple object test
-rw-r--r--tests/gobject/performance-threaded.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/tests/gobject/performance-threaded.c b/tests/gobject/performance-threaded.c
index 56a21eb2d..444a31794 100644
--- a/tests/gobject/performance-threaded.c
+++ b/tests/gobject/performance-threaded.c
@@ -23,6 +23,108 @@
#include "testcommon.h"
#define DEFAULT_TEST_TIME 2 /* seconds */
+/*************************************************************
+ * Instance object is *THE* simplest instance you can get.
+ *************************************************************/
+
+GType instance_get_type (void);
+#define INSTANCE_OBJECT (instance_object_get_type ())
+typedef struct _InstanceObject InstanceObject;
+typedef struct _InstanceObjectClass InstanceObjectClass;
+
+struct _InstanceObject
+{
+ GTypeInstance instance;
+};
+
+struct _InstanceObjectClass
+{
+ GTypeClass type_class;
+};
+
+
+static void
+instance_class_init (InstanceObjectClass *class)
+{
+ return;
+}
+
+static void
+instance_init (InstanceObject *instance)
+{
+ return;
+}
+
+GType instance_object_get_type (void)
+{
+ static GType inst_type = 0;
+ if (!inst_type) {
+ static const GTypeInfo inst_info = {
+ sizeof (InstanceObjectClass),
+ NULL, NULL, /* basE_init/base_finalize*/
+ (GClassInitFunc) instance_class_init,
+ NULL,
+ NULL,
+ sizeof (InstanceObject),
+ 0,
+ (GInstanceInitFunc) instance_init,
+ NULL
+ };
+ static const GTypeFundamentalInfo instance_fund_info = {
+ (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE |
+ G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
+ };
+ inst_type = g_type_fundamental_next ();
+ g_type_register_fundamental (inst_type, "Instance",
+ &inst_info, &instance_fund_info, 0);
+ }
+
+ return inst_type;
+}
+
+/*************************************************************
+ * Simple object is a very simple small GObject subclass
+ * with no properties, no signals, implementing no interfaces
+ *************************************************************/
+
+#define SIMPLE_TYPE_OBJECT (simple_object_get_type ())
+typedef struct _SimpleObject SimpleObject;
+typedef struct _SimpleObjectClass SimpleObjectClass;
+
+struct _SimpleObject
+{
+ GObject parent_instance;
+ int val;
+};
+
+struct _SimpleObjectClass
+{
+ GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (SimpleObject, simple_object, G_TYPE_OBJECT);
+
+static void
+simple_object_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (simple_object_parent_class)->finalize (object);
+}
+
+static void
+simple_object_class_init (SimpleObjectClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = simple_object_finalize;
+}
+
+static void
+simple_object_init (SimpleObject *simple_object)
+{
+ simple_object->val = 42;
+}
+
+
static GType
simple_register_class (const char *name, GType parent, ...)
@@ -138,6 +240,38 @@ liststore_interface_peek_same_run (gpointer klass)
}
}
+static gpointer
+instance_object_get_class_type (void)
+{
+ g_type_class_ref (INSTANCE_OBJECT);
+ return GINT_TO_POINTER (INSTANCE_OBJECT);
+}
+
+static gpointer
+simple_object_get_class_type (void)
+{
+ g_type_class_ref (SIMPLE_TYPE_OBJECT);
+ return GINT_TO_POINTER (SIMPLE_TYPE_OBJECT);
+}
+
+static void
+simple_creation_destruction_run (gpointer data)
+{
+ guint i;
+ for (i = 1000; i; i--) {
+ g_object_unref(g_object_new (GPOINTER_TO_INT (data), NULL));
+ }
+}
+
+static void
+instance_creation_destruction_run (gpointer data)
+{
+ guint i;
+ for (i = 1000; i; i--) {
+ g_type_free_instance(g_type_create_instance (GPOINTER_TO_INT (data)));
+ }
+}
+
#if 0
/* DUMB test doing nothing */
@@ -189,6 +323,26 @@ static const PerformanceTest tests[] = {
liststore_interface_peek_same_run,
no_reset,
g_type_class_unref },
+ { "instance-creation-destruction",
+ instance_object_get_type,
+ instance_creation_destruction_run,
+ no_reset,
+ no_teardown },
+ { "instance-creation-destruction-created",
+ instance_object_get_class_type,
+ instance_creation_destruction_run,
+ no_reset,
+ no_teardown },
+ { "simple-creation-destruction",
+ simple_object_get_type,
+ simple_creation_destruction_run,
+ no_reset,
+ no_teardown },
+ { "simple-creation-destruction-created",
+ simple_object_get_class_type,
+ simple_creation_destruction_run,
+ no_reset,
+ no_teardown },
#if 0
{ "nothing",
no_setup,