Debian Codegraph @

time_pyfribidi.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 """
4 time pyfribidi with all hebrew encodings.
5 """
6
7 import syspath
8 import timeit
9 import pyfribidi
10
11 hebrew_encodings = ['unicode', 'utf-8', 'utf-16', 'iso8859-8', 'cp1255']
12
13 def timeEncoding(encoding, tests):
14
15 setup="""
16 import pyfribidi
17 text = 'Hello - שלום, hello - שלום, hello - שלום, hello - שלום, hello - שלום.'
18 text = text.decode('utf-8')
19 if '%(encoding)s' != 'unicode':
20 text = text.encode('%(encoding)s')
21 """ % locals()
22
23 if encoding in ['unicode', 'utf-8']:
24 # utf-8 is the default encoding for strings
25 code = "pyfribidi.log2vis(text)"
26 else:
27 # other encodings require encoding parameter
28 code = "pyfribidi.log2vis(text, encoding='%s')" % encoding
29
30 timer = timeit.Timer(code, setup)
31 seconds = timer.timeit(number=tests)
32 microseconds = 1000000 * seconds / tests
33 print "%12s: %.8f seconds (%.2f usec/pass)" % (encoding, seconds,
34 microseconds)
35
36
37 # warm up caches
38 for i in xrange(100000):
39 pyfribidi.log2vis(u'Some text to warm up the caches')
40
41 lines = 50 # typical screen of text
42 print
43 print 'time to rerorder %s lines:' % lines
44 print
45 for encoding in hebrew_encodings:
46 timeEncoding(encoding, lines)
47
48 lines = 100000
49 print
50 print 'time to rerorder %s lines:' % lines
51 print
52 for encoding in hebrew_encodings:
53 timeEncoding(encoding, lines)