mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 19:00:08 +00:00
tree-performance: test with tree stores too
This duplicates the current test with a GtkTreeStore instead of a GtkListStore.
This commit is contained in:
parent
2deeab4c4f
commit
fb91fd7e3c
@ -22,7 +22,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
const gchar treeui[] =
|
||||
const gchar list_ui[] =
|
||||
"<interface>"
|
||||
" <object class='GtkListStore' id='liststore1'>"
|
||||
" <columns>"
|
||||
@ -125,7 +125,7 @@ builder_get_toplevel (GtkBuilder *builder)
|
||||
}
|
||||
|
||||
static void
|
||||
populate_tree (GtkBuilder *builder)
|
||||
populate_list (GtkBuilder *builder)
|
||||
{
|
||||
GtkTreeView *tv;
|
||||
GtkListStore *store;
|
||||
@ -143,6 +143,151 @@ populate_tree (GtkBuilder *builder)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_performance_list (void)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
gdouble elapsed;
|
||||
GtkWidget *window;
|
||||
GError *error = NULL;
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder, list_ui, -1, &error);
|
||||
g_assert_no_error (error);
|
||||
window = builder_get_toplevel (builder);
|
||||
g_assert (window);
|
||||
|
||||
gtk_widget_show (window);
|
||||
|
||||
g_test_timer_start ();
|
||||
|
||||
populate_list (builder);
|
||||
|
||||
elapsed = g_test_timer_elapsed ();
|
||||
g_test_minimized_result (elapsed, "large list test: %gsec", elapsed);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
static void
|
||||
test_a11y_performance_list (void)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
gdouble elapsed;
|
||||
GtkWidget *window;
|
||||
GError *error = NULL;
|
||||
gint count_before;
|
||||
gint count_after;
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder, list_ui, -1, &error);
|
||||
g_assert_no_error (error);
|
||||
window = builder_get_toplevel (builder);
|
||||
g_assert (window);
|
||||
|
||||
gtk_widget_show (window);
|
||||
|
||||
g_test_timer_start ();
|
||||
|
||||
/* make sure all accessibles exist */
|
||||
count_before = 0;
|
||||
walk_accessible_tree (gtk_widget_get_accessible (window), &count_before);
|
||||
|
||||
populate_list (builder);
|
||||
|
||||
/* for good measure, do this again */
|
||||
count_after = 0;
|
||||
walk_accessible_tree (gtk_widget_get_accessible (window), &count_after);
|
||||
|
||||
elapsed = g_test_timer_elapsed ();
|
||||
g_test_minimized_result (elapsed, "large list with a11y: %gsec", elapsed);
|
||||
g_object_unref (builder);
|
||||
|
||||
g_test_message ("%d accessibles before, %d after\n", count_before, count_after);
|
||||
}
|
||||
|
||||
const gchar tree_ui[] =
|
||||
"<interface>"
|
||||
" <object class='GtkTreeStore' id='treestore1'>"
|
||||
" <columns>"
|
||||
" <column type='gchararray'/>"
|
||||
" <column type='gchararray'/>"
|
||||
" <column type='gchararray'/>"
|
||||
" <column type='gboolean'/>"
|
||||
" <column type='gint'/>"
|
||||
" <column type='gint'/>"
|
||||
" </columns>"
|
||||
" </object>"
|
||||
" <object class='GtkWindow' id='window1'>"
|
||||
" <child>"
|
||||
" <object class='GtkTreeView' id='treeview1'>"
|
||||
" <property name='visible'>True</property>"
|
||||
" <property name='model'>treestore1</property>"
|
||||
" <child>"
|
||||
" <object class='GtkTreeViewColumn' id='column1'>"
|
||||
" <property name='title' translatable='yes'>First column</property>"
|
||||
" <child>"
|
||||
" <object class='GtkCellRendererText' id='renderer1'>"
|
||||
" </object>"
|
||||
" <attributes>"
|
||||
" <attribute name='text'>0</attribute>"
|
||||
" </attributes>"
|
||||
" </child>"
|
||||
" <child>"
|
||||
" <object class='GtkCellRendererToggle' id='renderer2'>"
|
||||
" </object>"
|
||||
" <attributes>"
|
||||
" <attribute name='active'>3</attribute>"
|
||||
" </attributes>"
|
||||
" </child>"
|
||||
" </object>"
|
||||
" </child>"
|
||||
" <child>"
|
||||
" <object class='GtkTreeViewColumn' id='column2'>"
|
||||
" <property name='title' translatable='yes'>Second column</property>"
|
||||
" <child>"
|
||||
" <object class='GtkCellRendererText' id='renderer3'>"
|
||||
" </object>"
|
||||
" <attributes>"
|
||||
" <attribute name='text'>1</attribute>"
|
||||
" </attributes>"
|
||||
" </child>"
|
||||
" <child>"
|
||||
" <object class='GtkCellRendererProgress' id='renderer4'>"
|
||||
" </object>"
|
||||
" <attributes>"
|
||||
" <attribute name='value'>4</attribute>"
|
||||
" </attributes>"
|
||||
" </child>"
|
||||
" </object>"
|
||||
" </child>"
|
||||
" </object>"
|
||||
" </child>"
|
||||
" </object>"
|
||||
"</interface>";
|
||||
|
||||
static void
|
||||
populate_tree (GtkBuilder *builder)
|
||||
{
|
||||
GtkTreeView *tv;
|
||||
GtkTreeStore *store;
|
||||
GtkTreeIter iter;
|
||||
gint i;
|
||||
|
||||
tv = (GtkTreeView *)gtk_builder_get_object (builder, "treeview1");
|
||||
store = (GtkTreeStore *)gtk_tree_view_get_model (tv);
|
||||
|
||||
/* append a thousand rows */
|
||||
for (i = 0; i < 333; i++)
|
||||
{
|
||||
gtk_tree_store_append (store, &iter, NULL);
|
||||
gtk_tree_store_set (store, &iter, 0, "Bla", 1, "Bla bla", 2, "Bla bla bla", 3, i % 2 == 0 ? TRUE : FALSE, 4, i % 100, 5, i, -1);
|
||||
gtk_tree_store_append (store, &iter, &iter);
|
||||
gtk_tree_store_set (store, &iter, 0, "Bla", 1, "Bla bla", 2, "Bla bla bla", 3, i % 2 == 0 ? TRUE : FALSE, 4, i % 100, 5, i, -1);
|
||||
gtk_tree_store_append (store, &iter, &iter);
|
||||
gtk_tree_store_set (store, &iter, 0, "Bla", 1, "Bla bla", 2, "Bla bla bla", 3, i % 2 == 0 ? TRUE : FALSE, 4, i % 100, 5, i, -1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_performance_tree (void)
|
||||
{
|
||||
@ -152,7 +297,7 @@ test_performance_tree (void)
|
||||
GError *error = NULL;
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder, treeui, -1, &error);
|
||||
gtk_builder_add_from_string (builder, tree_ui, -1, &error);
|
||||
g_assert_no_error (error);
|
||||
window = builder_get_toplevel (builder);
|
||||
g_assert (window);
|
||||
@ -179,7 +324,7 @@ test_a11y_performance_tree (void)
|
||||
gint count_after;
|
||||
|
||||
builder = gtk_builder_new ();
|
||||
gtk_builder_add_from_string (builder, treeui, -1, &error);
|
||||
gtk_builder_add_from_string (builder, tree_ui, -1, &error);
|
||||
g_assert_no_error (error);
|
||||
window = builder_get_toplevel (builder);
|
||||
g_assert (window);
|
||||
@ -199,7 +344,7 @@ test_a11y_performance_tree (void)
|
||||
walk_accessible_tree (gtk_widget_get_accessible (window), &count_after);
|
||||
|
||||
elapsed = g_test_timer_elapsed ();
|
||||
g_test_minimized_result (elapsed, "large tree test with a11y: %gsec", elapsed);
|
||||
g_test_minimized_result (elapsed, "large tree with a11y: %gsec", elapsed);
|
||||
g_object_unref (builder);
|
||||
|
||||
g_test_message ("%d accessibles before, %d after\n", count_before, count_after);
|
||||
@ -213,6 +358,8 @@ main (int argc, char *argv[])
|
||||
if (!g_test_perf ())
|
||||
return 0;
|
||||
|
||||
g_test_add_func ("/performance/list", test_performance_list);
|
||||
g_test_add_func ("/a11y/performance/list", test_a11y_performance_list);
|
||||
g_test_add_func ("/performance/tree", test_performance_tree);
|
||||
g_test_add_func ("/a11y/performance/tree", test_a11y_performance_tree);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user