#!/usr/bin/python import gtk import cairo import time TOTAL_CHARS = 96000 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 size in (10,24): print size, ": " for nchars in (1, 1, 5, 10, 30, 80): text = "A" * nchars result = [] total_chars = TOTAL_CHARS for repeat in (1,2,3): while True: 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(size) 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() if after - before < 0.5: total_chars *= 2 continue result.append((total_chars / (after - before))) break print "%d: %s" % (nchars, result)