#!/usr/bin/python from __future__ import division import gtk import cairo import time TOTAL_CHARS = 20000 cmap = gtk.gdk.screen_get_default().get_rgb_colormap() p = gtk.gdk.Pixmap(None, 100, 100, cmap.get_visual().depth) p.set_colormap(cmap) pbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1) for nchars in (1, 1, 5, 10, 20, 50): text = ("AB" * ((nchars + 1) // 2))[0:nchars] result = [] for repeat in (1,2,3): before = time.time() font_options = cairo.FontOptions() font_options.set_antialias(cairo.ANTIALIAS_GRAY) cr = p.cairo_create() cr.set_font_options(font_options) # cr.set_font_size(50) for i in xrange(0,TOTAL_CHARS // nchars): cr.move_to(0, 75) cr.show_text(text) pbuf.get_from_drawable(p, cmap, 0, 0, 0, 0, 1, 1) after = time.time() result.append((TOTAL_CHARS / (after - before))) print "%d: %s" % (nchars, result)