[gtk/wip/matthiasc/stringlist-array: 2/2] wip: benchmarks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/stringlist-array: 2/2] wip: benchmarks
- Date: Mon, 13 Jul 2020 00:55:49 +0000 (UTC)
commit 825b2a4139756d9f489fac6e424fbcb034ef851b
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Jul 1 14:04:43 2020 -0400
wip: benchmarks
testsuite/gtk/listmodel-performance.c | 91 +++++++++++++++++++++++++++++++++++
testsuite/gtk/meson.build | 1 +
2 files changed, 92 insertions(+)
---
diff --git a/testsuite/gtk/listmodel-performance.c b/testsuite/gtk/listmodel-performance.c
new file mode 100644
index 0000000000..e8654db12f
--- /dev/null
+++ b/testsuite/gtk/listmodel-performance.c
@@ -0,0 +1,91 @@
+#include <gtk/gtk.h>
+
+static GObject *
+get_object (const char *string)
+{
+ GtkStringList *list;
+ GObject *obj;
+
+ list = gtk_string_list_new ((const char *[]){string, NULL});
+ obj = g_list_model_get_item (G_LIST_MODEL (list), 0);
+ g_object_unref (list);
+
+ return obj;
+}
+
+static GListModel *
+make_store (guint n_items)
+{
+ GListStore *store;
+ guint i;
+
+ store = g_list_store_new (GTK_TYPE_STRING_OBJECT);
+
+ for (i = 0; i < n_items; i++)
+ {
+ char *string;
+ GObject *obj;
+
+ string = g_strdup_printf ("item %d", i);
+ obj = get_object (string);
+ g_list_store_append (store, obj);
+ g_object_unref (obj);
+ g_free (string);
+ }
+
+ return G_LIST_MODEL (store);
+}
+
+static void
+do_random_access (guint size)
+{
+ GListModel *model;
+ guint i;
+ guint position;
+ GtkStringObject *obj;
+ gint64 start, end;
+ guint iterations = 10000000;
+
+ model = make_store (size);
+
+ start = g_get_monotonic_time ();
+
+ for (i = 0; i < iterations; i++)
+ {
+ position = g_random_int_range (0, size);
+ obj = g_list_model_get_item (model, position);
+ if (g_getenv ("PRINT_ACCESS"))
+ g_print ("%s", gtk_string_object_get_string (obj));
+ g_object_unref (obj);
+ }
+
+ end = g_get_monotonic_time ();
+
+ g_print ("size %u: %g accesses per second\n",
+ size,
+ (iterations / (double) G_TIME_SPAN_SECOND) * ((double)(end - start)));
+
+ g_object_unref (model);
+}
+
+static void
+random_access (void)
+{
+ do_random_access (1e1);
+ do_random_access (1e2);
+ do_random_access (1e3);
+ do_random_access (1e4);
+ do_random_access (1e5);
+ do_random_access (1e6);
+ do_random_access (1e7);
+}
+
+int
+main (int argc, char *argv[])
+{
+ gtk_test_init (&argc, &argv);
+
+ g_test_add_func ("/liststore/random-access", random_access);
+
+ return g_test_run ();
+}
diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build
index cee96704db..26ed064f5d 100644
--- a/testsuite/gtk/meson.build
+++ b/testsuite/gtk/meson.build
@@ -76,6 +76,7 @@ tests = [
['revealer-size'],
['widgetorder'],
['widget-refcount'],
+ ['listmodel-performance'],
]
# Tests that are expected to fail
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]