4 This is a framework for testing performance in GTK+. For GTK+, being
5 performant does not only mean "paint widgets fast". It also means
6 things like the time needed to set up widgets, to map and draw a
7 window for the first time, and emitting/propagating signals.
9 The following is accurate as of 2005/07/26.
15 Right now the framework is very simple; it just has utility functions
16 to time widget creation, drawing, and destruction. To run such a
17 test, you use the functions in timers.h. You can call this:
19 timer_time_widget (create_func, report_func, user_data);
21 You must provide the create_funcn and report_func callbacks.
25 This simply creates a toplevel window with some widgets inside it.
26 It is important that you do not show any of the widgets; the
27 framework will call gtk_widget_show_all() on the toplevel window
28 automatically at the right time.
32 This function will get called when timer_time_widget() reaches an
33 interesting point in the lifecycle of your widget. See timers.h and
34 the TimerReport enumeration; this is what gets passed as the
35 "report" argument to your report_func. Right now, your function
36 will be called three times for each call to timer_time_widget():
38 1. With report = TIMER_REPORT_WIDGET_CREATION. A timer gets
39 started right before timer_time_widget() calls create_func,
40 and it gets stopped when your create_func returns. This
41 measures the time it takes to set up a toplevel window (but
44 2. With report = TIMER_REPORT_WIDGET_SHOW. A timer gets started
45 right before timer_time_widget() calls gtk_widget_show_all()
46 on your toplevel window, and it gets stopped when the window
47 has been fully shown and painted to the screen.
49 3. With report = TIMER_REPORT_WIDGET_DESTRUCTION. A timer gets
50 started right before timer_time_widget() calls
51 gtk_widget_destroy() on your toplevel window, and it gets
52 stopped when gtk_widget_destroy() returns.
54 As a very basic example of using timer_time_widget(), you can use
57 ----------------------------------------------------------------------
65 create_cb (gpointer data)
69 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
70 /* ... fill the window with widgets, and don't show them ... */
76 report_cb (TimerReport report, gdouble elapsed, gpointer data)
81 case TIMER_REPORT_WIDGET_CREATION:
82 type = "widget creation";
85 case TIMER_REPORT_WIDGET_SHOW:
89 case TIMER_REPORT_WIDGET_DESTRUCTION:
90 type = "widget destruction";
94 fprintf (stderr, "%s: %g sec\n", type, elapsed);
98 main (int argc, char **argv)
102 gtk_init (&argc, &argv);
104 for (i = 0; i < ITERS; i++)
105 timer_time_widget (create_cb, report_cb, NULL);
109 ----------------------------------------------------------------------
112 Getting meaningful results
113 --------------------------
115 Getting times for widget creation/drawing/destruction is interesting,
116 but how do you actually find the places that need optimizing?
118 Why, you run the tests under a profiler, of course.
120 FIXME: document how to do this.
126 Please mail your feedback to Federico Mena-Quintero <federico@novell.com>.
127 This performance framework is a work in progress.