testgtk bench facility
- From: Hans Breuer <hans breuer org>
- To: gtk-devel-list gnome org
- Subject: testgtk bench facility
- Date: Sat, 04 Aug 2001 17:25:03 +0200
IMHO one of the main issues of gtk+2.0 compared to the gtk-1.2
and early gtk-1.3 series is performance. This is where I see
adding a simple benchmark facility become handy.
The following patch does provide the ability to benchmark
the construction of single widgets by simply passing there
buttons name on the command line, like:
testgtk bench:labels <n>
(the optional n does allow to produce the average timing of
multiple calls.)
It then calls the respective function, 'waits' with gdk_flush()
and calls the function again (which almost always destroys the
widget). The timing is g_print than and testgtk exits. The above
examples produces the following output:
"labels" took 2700.0 ms
Objections against adding this facility ?
Hans
--- from-cvs/gtk+/tests/testgtk.c Fri Aug 03 12:47:10 2001
+++ my-gtk/gtk+/tests/testgtk.c Sat Aug 04 17:05:50 2001
@@ -10249,9 +10249,6 @@
gtk_main_quit ();
}
-void
-create_main_window (void)
-{
struct {
char *label;
void (*func) ();
@@ -10316,6 +10313,10 @@
{ "window states", create_window_states }
};
int nbuttons = sizeof (buttons) / sizeof (buttons[0]);
+
+void
+create_main_window (void)
+{
GtkWidget *window;
GtkWidget *box1;
GtkWidget *box2;
@@ -10420,10 +10421,65 @@
}
}
+void
+do_real_bench (void (* fn) (), char *name, int num)
+{
+ GTimeVal tv0, tv1;
+ float dt;
+ int n;
+
+ g_get_current_time (&tv0);
+ for (n = 0; n < num; n++)
+ {
+ fn (); /* on */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+ fn (); /* off */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+ }
+ g_get_current_time (&tv1);
+ dt = ((float)tv1.tv_sec - tv0.tv_sec) * 1000.0
+ + (tv1.tv_usec - tv0.tv_usec) / 1000.0;
+
+ g_print ("\"%s\" took\t%.1f ms\n", name, dt/num);
+}
+
+void
+do_bench (char* what, int num)
+{
+ int i, n;
+ void (* fn) ();
+ fn = NULL;
+
+ if (what == NULL)
+ {
+ for (i = 0; i < nbuttons; i++)
+ do_real_bench (buttons[i].func, buttons[i].label, num);
+
+ return;
+ }
+
+ for (i = 0; i < nbuttons; i++)
+ {
+ if (strcmp (buttons[i].label, what) == 0)
+ {
+ fn = buttons[i].func;
+ break;
+ }
+ }
+
+ if (!fn)
+ g_print ("Can't bench: \"%s\" not found.\n", what);
+ else
+ do_real_bench (fn, buttons[i].label, num);
+}
+
int
main (int argc, char *argv[])
{
GtkBindingSet *binding_set;
+ int i;
srand (time (NULL));
@@ -10437,6 +10493,27 @@
gtk_rc_add_default_file ("testgtkrc");
gtk_init (&argc, &argv);
+
+ /* benchmarking
+ */
+ for (i = 1; i < argc; i++)
+ {
+ if (argv[i] && strncmp (argv[i], "bench", strlen("bench")) == 0)
+ {
+ int num = 1;
+ char *what = strstr(argv[i], ":");
+ if (what)
+ what++;
+ if (i + 1 < argc)
+ num = atoi(argv[i+1]);
+ if (num > 0)
+ i++; /* skip as input */
+
+ do_bench (what, num ? num : 1);
+ }
+ }
+ if (argc > 1)
+ return 0; /* is this too drastic ? */
/* bindings test
*/
-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it. -- Dilbert
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]