Compare commits

...

5 Commits

Author SHA1 Message Date
Matthias Clasen
155899a1e4 Revert "stringlist: Use an array"
This reverts commit bf367b219b.
2020-07-01 14:05:16 -04:00
Matthias Clasen
70cbdd138a Revert "stringlist: Try to reuse objects"
This reverts commit 31404c5d2f.
2020-07-01 14:05:07 -04:00
Matthias Clasen
3e1b9703e7 wip: benchmarks 2020-07-01 14:04:59 -04:00
Matthias Clasen
31404c5d2f stringlist: Try to reuse objects
Try a few nearby positions to see if they have
unused objects, and if so, steal one. This avoids
object growth when filtering, but does not help
for scrolling.
2020-06-30 23:52:10 -04:00
Matthias Clasen
bf367b219b stringlist: Use an array
A version of GtkStringList that uses a GPtrArray
to hold the strings / objects. We avoid a second
array by marking strings using a low bit of the
pointer.
2020-06-30 23:37:21 -04:00
2 changed files with 92 additions and 0 deletions

View File

@@ -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 ();
}

View File

@@ -76,6 +76,7 @@ tests = [
['revealer-size'],
['widgetorder'],
['widget-refcount'],
['listmodel-performance'],
]
# Tests that are expected to fail