Re: high-level text drawing



Tom Liu wrote:

Hi Olexiy:
Attatch is the program I make for the test. You may try it and will find what's wrong with this test
program.
        
        I run this program on a sun box and the Xserver is Exceed7.1.1.
You should not create/destroy layout and set layout's font in your test because you dont use XLoadFont or so... I've done some testing (sample attached), my results: ~100 times with Xft backend and ~20 times with GDK_USE_XFT=0 (XFree86-4.3.0 NVIDIA driver NV17 chip, P4 1.8GHz portable).

PS: I was really surprised, my older measurements were much better ;)

   Olexiy
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>


static GtkWidget *label;
static GtkWidget *area;
static GtkWidget *spin;


static void run_test()
{
gint            i, count;
gchar           s[256];
gdouble         t0, t1;
GTimer          *timer;
PangoLayout     *pl;

        count = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
        timer = g_timer_new();

        pl = gtk_widget_create_pango_layout(area, NULL);

        g_timer_start(timer);
        for (i=0;i<count;i++) {
                sprintf(s, "str%d", i);
                pango_layout_set_text(pl, s, -1);
                gdk_draw_layout(area->window, area->style->black_gc, 0,0, pl);
        }
        gdk_flush();
        g_timer_stop(timer);
        g_object_unref(pl);

        t0 = g_timer_elapsed(timer, NULL);

        g_timer_start(timer);
        for (i=0;i<count;i++) {
                sprintf(s, "str%d", i);
                XDrawString(GDK_DISPLAY(), GDK_DRAWABLE_XID(area->window), GDK_GC_XGC(area->style->black_gc), 
0,0, s, strlen(s));
        }
        gdk_flush();
        g_timer_stop(timer);

        t1 = g_timer_elapsed(timer, NULL);

        sprintf(
                s,
                "gdk_draw_layout: %fms total, %fus per string\n"\
                "XDrawString: %fms total, %fus per string\n\n"\
                "gdk_draw_layout/XDrawString: %f\n",
                t0/1000.0, t0*1000.0*1000.0/count,
                t1/1000.0, t1*1000.0*1000.0/count,
                t0/t1
        );

        gtk_label_set_text(GTK_LABEL(label), s);

        g_timer_destroy(timer);
}

int main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *button;

        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width(GTK_CONTAINER(window), 4);
        g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), 0);

        vbox = gtk_vbox_new(FALSE, 4);
        gtk_container_add(GTK_CONTAINER(window), vbox);

        area = gtk_drawing_area_new();
        gtk_widget_set_size_request(area, 256,64);
        gtk_box_pack_start(GTK_BOX(vbox), area, FALSE,FALSE, 0);

        label = gtk_label_new("[ press execute to run test ]");
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE,FALSE, 0);

        hbox = gtk_hbox_new(FALSE, 4);
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE,FALSE, 0);

        gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new("N tests:"), FALSE,FALSE, 0);

        spin = gtk_spin_button_new_with_range(1024,128*1024, 1024);
        gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE,FALSE, 0);

        button = gtk_button_new_from_stock(GTK_STOCK_EXECUTE);
        gtk_box_pack_start(GTK_BOX(hbox), button, FALSE,FALSE, 0);
        g_signal_connect(button, "clicked", G_CALLBACK(run_test), 0);

        gtk_widget_show_all(window);
        gtk_main();

        return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]