Container performance
- From: digicapt - gtk dev <gtk digicapt ch>
- To: gtk-list gnome org
- Subject: Container performance
- Date: Sat, 01 Dec 2007 11:28:14 +0100
I'm using GTK+2.0.21 on a Fedora Core 6 and I need to create containers with a
lot of widgets.
If you try following code, you'll see that filling a container with 4000
entries (first button) is about 20 times slower than filling a container with
4000 labels (second button) : 1 seconds for labels on my PC, 20 seconds for
the edits.
Note you have to restart application between tests.
Can somebody tell me if there is a way to get the same performance with
entries ? I would even be glad with a twice slower performance :)
Regards,
Blaise
#include <stdio.h>
#include <gtk/gtk.h>
GtkWindow *frame;
GtkBox *framelayout;
GtkScrolledWindow *panel;
void buttonGridClick(GtkButton *i_button,
gpointer i_data);
void buttonGridLabelClick(GtkButton *i_button,
gpointer i_data);
void buttonBoxClick(GtkButton *i_button,
gpointer i_data);
int main(int argc,
char *argv[]) {
GtkViewport *viewport;
GtkButton *buttongrid;
GtkButton *buttongridlabel;
GtkButton *buttonbox;
gtk_init(&argc,
&argv);
// Frame
frame = (GtkWindow *) gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize((GtkWidget *) frame,
400, 600);
gtk_window_set_policy((GtkWindow *) frame,
true, true, false);
framelayout = (GtkBox *) gtk_vbox_new(false, 0);
gtk_container_add((GtkContainer *) frame,
(GtkWidget *) framelayout);
gtk_widget_show((GtkWidget *) framelayout);
// Button grid
buttongrid = (GtkButton *) gtk_button_new_with_label("Add 1000 * 4 items as
grid");
gtk_widget_set_usize((GtkWidget *) buttongrid,
-1, -1);
gtk_box_pack_start(framelayout,
(GtkWidget *) buttongrid,
false, false,
0);
gtk_widget_show((GtkWidget *) buttongrid);
// Button grid label
buttongridlabel = (GtkButton *) gtk_button_new_with_label("Add 1000 * 4
labels as grid");
gtk_widget_set_usize((GtkWidget *) buttongridlabel,
-1, -1);
gtk_box_pack_start(framelayout,
(GtkWidget *) buttongridlabel,
false, false,
0);
gtk_widget_show((GtkWidget *) buttongridlabel);
// Button box
buttonbox = (GtkButton *) gtk_button_new_with_label("Add 1000 * 4 items as
box");
gtk_widget_set_usize((GtkWidget *) buttonbox,
-1, -1);
gtk_box_pack_start(framelayout,
(GtkWidget *) buttonbox,
false, false,
0);
gtk_widget_show((GtkWidget *) buttonbox);
// Panel
panel = (GtkScrolledWindow *) gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_usize((GtkWidget *) panel,
-1, -1);
gtk_scrolled_window_set_policy(panel,
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
///gtk_container_set_reallocate_redraws((GtkContainer *) panel, true);
//viewport = (GtkViewport *) gtk_bin_get_child((GtkBin *) panel);
//gtk_viewport_set_shadow_type(viewport, GTK_SHADOW_OUT);
gtk_widget_show((GtkWidget *) panel);
gtk_box_pack_start(framelayout,
(GtkWidget *) panel,
true, true,
0);
// Button event
gtk_signal_connect((GtkObject *) buttongrid,
"clicked",
GTK_SIGNAL_FUNC(buttonGridClick),
NULL);
gtk_signal_connect((GtkObject *) buttongridlabel,
"clicked",
GTK_SIGNAL_FUNC(buttonGridLabelClick),
NULL);
gtk_signal_connect((GtkObject *) buttonbox,
"clicked",
GTK_SIGNAL_FUNC(buttonBoxClick),
NULL);
// Show frame
gtk_widget_show((GtkWidget *) frame);
gtk_main();
}
/*
* Event - buttons
*/
void buttonGridClick(GtkButton *i_button,
gpointer i_data) {
GtkTable *layout;
GtkEntry *edit;
int i;
int j;
layout = (GtkTable *) gtk_table_new(4, 1000, false);
gtk_scrolled_window_add_with_viewport(panel,
(GtkWidget *) layout);
gtk_widget_show((GtkWidget *) layout);
for (i = 0 ; i < 1000 ; i++)
for (j = 0 ; j < 4 ; j++) {
edit = (GtkEntry *) gtk_entry_new();
gtk_table_attach(layout,
(GtkWidget *) edit,
j, j + 1,
i, i + 1,
(GtkAttachOptions) 0,
(GtkAttachOptions) 0,
0, 0);
gtk_widget_show((GtkWidget *) edit);
}
}
/*
* Event - buttons
*/
void buttonGridLabelClick(GtkButton *i_button,
gpointer i_data) {
GtkTable *layout;
GtkLabel *label;
int i;
int j;
layout = (GtkTable *) gtk_table_new(4, 1000, false);
gtk_scrolled_window_add_with_viewport(panel,
(GtkWidget *) layout);
gtk_widget_show((GtkWidget *) layout);
for (i = 0 ; i < 1000 ; i++)
for (j = 0 ; j < 4 ; j++) {
label = (GtkLabel *) gtk_label_new("TEST");
gtk_table_attach(layout,
(GtkWidget *) label,
j, j + 1,
i, i + 1,
(GtkAttachOptions) 0,
(GtkAttachOptions) 0,
0, 0);
gtk_widget_show((GtkWidget *) label);
}
}
/*
* Event - buttons
*/
void buttonBoxClick(GtkButton *i_button,
gpointer i_data) {
GtkBox *rowlayout;
GtkBox *collayout;
GtkEntry *edit;
int i;
int j;
rowlayout = (GtkBox *) gtk_vbox_new(false, 0);
gtk_scrolled_window_add_with_viewport(panel,
(GtkWidget *) rowlayout);
gtk_widget_show((GtkWidget *) rowlayout);
for (i = 0 ; i < 1000 ; i++) {
collayout = (GtkBox *) gtk_hbox_new(false, 0);
gtk_box_pack_start(rowlayout,
(GtkWidget *) collayout,
false, false,
0);
gtk_widget_show((GtkWidget *) collayout);
for (j = 0 ; j < 4 ; j++) {
edit = (GtkEntry *) gtk_entry_new();
gtk_widget_set_usize((GtkWidget *) edit,
50, 24);
gtk_box_pack_start(collayout,
(GtkWidget *) edit,
false, false,
0);
gtk_widget_show((GtkWidget *) edit);
}
}
}
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]