~ubuntu-branches/ubuntu/trusty/python-enable/trusty

« back to all changes in this revision

Viewing changes to enthought/kiva/agg/tests/font_loading_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-05 21:54:28 UTC
  • mfrom: (1.1.5 upstream)
  • mto: (8.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20110405215428-1x2wtubz3ok2kxaq
Tags: upstream-3.4.1
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from string import lowercase, uppercase
2
 
import os
3
 
import time
4
 
 
5
 
from enthought.kiva.backend_image import font_metrics_provider as FMP
6
 
from enthought.kiva.fonttools import Font
7
 
 
8
 
counts = (500,)
9
 
strings = ("hello", ) # lowercase + uppercase)
10
 
fonts = ( ("arial", 12), ) # ("times", 16), ("courier", 10) )
11
 
 
12
 
def test():
13
 
 
14
 
    allmetrics = []
15
 
    for count in counts:
16
 
        start = time.time()
17
 
        for i in range(count):
18
 
            metrics = FMP()
19
 
            for face, size in fonts:
20
 
                metrics.set_font(Font(face, size))
21
 
                for s in strings:
22
 
                    dims = metrics.get_text_extent(s)
23
 
            allmetrics.append(metrics)
24
 
        end = time.time()
25
 
        print "finished count=%d" % count
26
 
        print "   total time:", end - start
27
 
        print "   time/set_font:", (end-start) / float(count * len(fonts))
28
 
 
29
 
if __name__ == "__main__":
30
 
    test()
 
1
from string import lowercase, uppercase
 
2
import os
 
3
import time
 
4
 
 
5
from enthought.kiva.image import font_metrics_provider as FMP
 
6
from enthought.kiva.fonttools import Font
 
7
 
 
8
counts = (500,)
 
9
strings = ("hello", ) # lowercase + uppercase)
 
10
fonts = ( ("arial", 12), ) # ("times", 16), ("courier", 10) )
 
11
 
 
12
def test():
 
13
 
 
14
    allmetrics = []
 
15
    for count in counts:
 
16
        start = time.time()
 
17
        for i in range(count):
 
18
            metrics = FMP()
 
19
            for face, size in fonts:
 
20
                metrics.set_font(Font(face, size))
 
21
                for s in strings:
 
22
                    dims = metrics.get_text_extent(s)
 
23
            allmetrics.append(metrics)
 
24
        end = time.time()
 
25
        print "finished count=%d" % count
 
26
        print "   total time:", end - start
 
27
        print "   time/set_font:", (end-start) / float(count * len(fonts))
 
28
 
 
29
if __name__ == "__main__":
 
30
    test()