/** * Test application to benchmark listing all fonts from pango. * gcc -o listpangofonts listpangofonts.c `pkg-config --cflags --libs gtk+-2.0` */ #include #include #include #include /* Returns the difference between two timestamps in microseconds. */ static int timediff (struct timeval *large, struct timeval *small) { return ( ( ( large->tv_sec * 1000 * 1000 ) + large->tv_usec ) - ( ( small->tv_sec * 1000 * 1000 ) + small->tv_usec ) ); } int main( int argc, char **argv ) { GtkWidget *window, *label; PangoFontFamily **families; struct timeval before; struct timeval after; int nfam, i, curtime; int total = 0; int nfonts = 0; /* Initialize GTK+ enough so we can get a pango context. */ gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); label = gtk_label_new ("hi there"); gtk_container_add (GTK_CONTAINER (window), label); gtk_widget_show_all (window); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), 0); gettimeofday (&before, 0); pango_context_list_families (gtk_widget_get_pango_context (label), &families, &nfam); gettimeofday (&after, 0); curtime = timediff (&after, &before); total += curtime; fprintf (stderr, "%d families (%d us)\n", nfam, curtime); for (i = 0; i < nfam; i++) { PangoFontFace **faces; int nfaces, j; gettimeofday (&before, 0); pango_font_family_list_faces (families[i], &faces, &nfaces); gettimeofday (&after, 0); curtime = timediff (&after, &before); total += curtime; fprintf (stderr, "%s: %d faces (%d us)\n", pango_font_family_get_name (families[i]), nfaces, curtime); for (j = 0; j < nfaces; j++ ) { PangoFontDescription *desc; gettimeofday (&before, 0); desc = pango_font_face_describe (faces[j]); gettimeofday (&after, 0); curtime = timediff (&after, &before); total += curtime; fprintf (stderr, "\t%s (%d us)\n", pango_font_face_get_face_name (faces[j]), curtime); nfonts++; pango_font_description_free (desc); } g_free (faces); } g_free (families); fprintf (stderr, "list took %d ms in total on %d families (%d fonts)\n", total / 1000, nfam, nfonts); return 0; }