File: font_loading_test.py

package info (click to toggle)
python-enable 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,220 kB
  • sloc: cpp: 57,417; python: 28,437; makefile: 314; sh: 43
file content (30 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from string import lowercase, uppercase
import os
import time

from kiva.image import font_metrics_provider as FMP
from kiva.fonttools import Font

counts = (500,)
strings = ("hello", ) # lowercase + uppercase)
fonts = ( ("arial", 12), ) # ("times", 16), ("courier", 10) )

def test():

    allmetrics = []
    for count in counts:
        start = time.time()
        for i in range(count):
            metrics = FMP()
            for face, size in fonts:
                metrics.set_font(Font(face, size))
                for s in strings:
                    dims = metrics.get_text_extent(s)
            allmetrics.append(metrics)
        end = time.time()
        print "finished count=%d" % count
        print "   total time:", end - start
        print "   time/set_font:", (end-start) / float(count * len(fonts))

if __name__ == "__main__":
    test()