annotate Tools/pybench/pybench.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 1acd00f2a380
children abbc797575c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
1 #!/usr/local/bin/python -O
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
2
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
3 """ A Python Benchmark Suite
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
4
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
5 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
6 #
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
7 # Note: Please keep this module compatible to Python 1.5.2.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
8 #
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
9 # Tests may include features in later Python versions, but these
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
10 # should then be embedded in try-except clauses in the configuration
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
11 # module Setup.py.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
12 #
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
13
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
14 # pybench Copyright
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
15 __copyright__ = """\
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
16 Copyright (c), 1997-2006, Marc-Andre Lemburg (mal@lemburg.com)
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
17 Copyright (c), 2000-2006, eGenix.com Software GmbH (info@egenix.com)
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
18
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
19 All Rights Reserved.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
20
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
21 Permission to use, copy, modify, and distribute this software and its
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
22 documentation for any purpose and without fee or royalty is hereby
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
23 granted, provided that the above copyright notice appear in all copies
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
24 and that both that copyright notice and this permission notice appear
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
25 in supporting documentation or portions thereof, including
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
26 modifications, that you make.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
27
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
28 THE AUTHOR MARC-ANDRE LEMBURG DISCLAIMS ALL WARRANTIES WITH REGARD TO
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
29 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
30 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
31 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
32 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
33 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
34 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
35 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
36
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
37 import sys, time, operator, string, platform
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
38 from CommandLine import *
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
39
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
40 try:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
41 import cPickle
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
42 pickle = cPickle
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
43 except ImportError:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
44 import pickle
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
45
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
46 # Version number; version history: see README file !
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
47 __version__ = '2.0'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
48
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
49 ### Constants
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
50
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
51 # Second fractions
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
52 MILLI_SECONDS = 1e3
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
53 MICRO_SECONDS = 1e6
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
54
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
55 # Percent unit
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
56 PERCENT = 100
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
57
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
58 # Horizontal line length
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
59 LINE = 79
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
60
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
61 # Minimum test run-time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
62 MIN_TEST_RUNTIME = 1e-3
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
63
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
64 # Number of calibration runs to use for calibrating the tests
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
65 CALIBRATION_RUNS = 20
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
66
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
67 # Number of calibration loops to run for each calibration run
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
68 CALIBRATION_LOOPS = 20
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
69
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
70 # Allow skipping calibration ?
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
71 ALLOW_SKIPPING_CALIBRATION = 1
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
72
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
73 # Timer types
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
74 TIMER_TIME_TIME = 'time.time'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
75 TIMER_TIME_CLOCK = 'time.clock'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
76 TIMER_SYSTIMES_PROCESSTIME = 'systimes.processtime'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
77
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
78 # Choose platform default timer
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
79 if sys.platform[:3] == 'win':
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
80 # On WinXP this has 2.5ms resolution
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
81 TIMER_PLATFORM_DEFAULT = TIMER_TIME_CLOCK
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
82 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
83 # On Linux this has 1ms resolution
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
84 TIMER_PLATFORM_DEFAULT = TIMER_TIME_TIME
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
85
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
86 # Print debug information ?
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
87 _debug = 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
88
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
89 ### Helpers
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
90
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
91 def get_timer(timertype):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
92
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
93 if timertype == TIMER_TIME_TIME:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
94 return time.time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
95 elif timertype == TIMER_TIME_CLOCK:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
96 return time.clock
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
97 elif timertype == TIMER_SYSTIMES_PROCESSTIME:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
98 import systimes
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
99 return systimes.processtime
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
100 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
101 raise TypeError('unknown timer type: %s' % timertype)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
102
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
103 def get_machine_details():
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
104
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
105 if _debug:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
106 print 'Getting machine details...'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
107 buildno, builddate = platform.python_build()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
108 python = platform.python_version()
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
109 try:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
110 unichr(100000)
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
111 except ValueError:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
112 # UCS2 build (standard)
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
113 unicode = 'UCS2'
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
114 except NameError:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
115 unicode = None
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
116 else:
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
117 # UCS4 build (most recent Linux distros)
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
118 unicode = 'UCS4'
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
119 bits, linkage = platform.architecture()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
120 return {
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
121 'platform': platform.platform(),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
122 'processor': platform.processor(),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
123 'executable': sys.executable,
45719
5b4239c1f8f8 Well that was dumb. platform.python_implementation returns a function, not a
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 45718
diff changeset
124 'implementation': getattr(platform, 'python_implementation',
5b4239c1f8f8 Well that was dumb. platform.python_implementation returns a function, not a
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 45718
diff changeset
125 lambda:'n/a')(),
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
126 'python': platform.python_version(),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
127 'compiler': platform.python_compiler(),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
128 'buildno': buildno,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
129 'builddate': builddate,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
130 'unicode': unicode,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
131 'bits': bits,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
132 }
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
133
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
134 def print_machine_details(d, indent=''):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
135
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
136 l = ['Machine Details:',
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
137 ' Platform ID: %s' % d.get('platform', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
138 ' Processor: %s' % d.get('processor', 'n/a'),
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
139 '',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
140 'Python:',
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
141 ' Implementation: %s' % d.get('implementation', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
142 ' Executable: %s' % d.get('executable', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
143 ' Version: %s' % d.get('python', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
144 ' Compiler: %s' % d.get('compiler', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
145 ' Bits: %s' % d.get('bits', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
146 ' Build: %s (#%s)' % (d.get('builddate', 'n/a'),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
147 d.get('buildno', 'n/a')),
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
148 ' Unicode: %s' % d.get('unicode', 'n/a'),
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
149 ]
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
150 print indent + string.join(l, '\n' + indent) + '\n'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
151
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
152 ### Test baseclass
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
153
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
154 class Test:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
155
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
156 """ All test must have this class as baseclass. It provides
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
157 the necessary interface to the benchmark machinery.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
158
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
159 The tests must set .rounds to a value high enough to let the
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
160 test run between 20-50 seconds. This is needed because
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
161 clock()-timing only gives rather inaccurate values (on Linux,
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
162 for example, it is accurate to a few hundreths of a
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
163 second). If you don't want to wait that long, use a warp
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
164 factor larger than 1.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
165
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
166 It is also important to set the .operations variable to a
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
167 value representing the number of "virtual operations" done per
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
168 call of .run().
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
169
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
170 If you change a test in some way, don't forget to increase
41087
Georg Brandl <georg@python.org>
parents: 40623
diff changeset
171 its version number.
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
172
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
173 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
174
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
175 ### Instance variables that each test should override
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
176
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
177 # Version number of the test as float (x.yy); this is important
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
178 # for comparisons of benchmark runs - tests with unequal version
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
179 # number will not get compared.
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
180 version = 2.0
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
181
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
182 # The number of abstract operations done in each round of the
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
183 # test. An operation is the basic unit of what you want to
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
184 # measure. The benchmark will output the amount of run-time per
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
185 # operation. Note that in order to raise the measured timings
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
186 # significantly above noise level, it is often required to repeat
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
187 # sets of operations more than once per test round. The measured
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
188 # overhead per test round should be less than 1 second.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
189 operations = 1
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
190
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
191 # Number of rounds to execute per test run. This should be
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
192 # adjusted to a figure that results in a test run-time of between
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
193 # 1-2 seconds.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
194 rounds = 100000
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
195
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
196 ### Internal variables
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
197
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
198 # Mark this class as implementing a test
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
199 is_a_test = 1
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
200
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
201 # Last timing: (real, run, overhead)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
202 last_timing = (0.0, 0.0, 0.0)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
203
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
204 # Warp factor to use for this test
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
205 warp = 1
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
206
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
207 # Number of calibration runs to use
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
208 calibration_runs = CALIBRATION_RUNS
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
209
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
210 # List of calibration timings
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
211 overhead_times = None
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
212
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
213 # List of test run timings
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
214 times = []
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
215
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
216 # Timer used for the benchmark
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
217 timer = TIMER_PLATFORM_DEFAULT
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
218
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
219 def __init__(self, warp=None, calibration_runs=None, timer=None):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
220
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
221 # Set parameters
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
222 if warp is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
223 self.rounds = int(self.rounds / warp)
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
224 if self.rounds == 0:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
225 raise ValueError('warp factor set too high')
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
226 self.warp = warp
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
227 if calibration_runs is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
228 if (not ALLOW_SKIPPING_CALIBRATION and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
229 calibration_runs < 1):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
230 raise ValueError('at least one calibration run is required')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
231 self.calibration_runs = calibration_runs
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
232 if timer is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
233 timer = timer
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
234
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
235 # Init variables
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
236 self.times = []
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
237 self.overhead_times = []
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
238
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
239 # We want these to be in the instance dict, so that pickle
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
240 # saves them
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
241 self.version = self.version
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
242 self.operations = self.operations
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
243 self.rounds = self.rounds
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
244
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
245 def get_timer(self):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
246
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
247 """ Return the timer function to use for the test.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
248
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
249 """
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
250 return get_timer(self.timer)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
251
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
252 def compatible(self, other):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
253
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
254 """ Return 1/0 depending on whether the test is compatible
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
255 with the other Test instance or not.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
256
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
257 """
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
258 if self.version != other.version:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
259 return 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
260 if self.rounds != other.rounds:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
261 return 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
262 return 1
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
263
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
264 def calibrate_test(self):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
265
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
266 if self.calibration_runs == 0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
267 self.overhead_times = [0.0]
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
268 return
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
269
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
270 calibrate = self.calibrate
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
271 timer = self.get_timer()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
272 calibration_loops = range(CALIBRATION_LOOPS)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
273
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
274 # Time the calibration loop overhead
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
275 prep_times = []
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
276 for i in range(self.calibration_runs):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
277 t = timer()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
278 for i in calibration_loops:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
279 pass
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
280 t = timer() - t
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
281 prep_times.append(t)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
282 min_prep_time = min(prep_times)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
283 if _debug:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
284 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
285 print 'Calib. prep time = %.6fms' % (
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
286 min_prep_time * MILLI_SECONDS)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
287
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
288 # Time the calibration runs (doing CALIBRATION_LOOPS loops of
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
289 # .calibrate() method calls each)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
290 for i in range(self.calibration_runs):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
291 t = timer()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
292 for i in calibration_loops:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
293 calibrate()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
294 t = timer() - t
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
295 self.overhead_times.append(t / CALIBRATION_LOOPS
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
296 - min_prep_time)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
297
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
298 # Check the measured times
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
299 min_overhead = min(self.overhead_times)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
300 max_overhead = max(self.overhead_times)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
301 if _debug:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
302 print 'Calib. overhead time = %.6fms' % (
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
303 min_overhead * MILLI_SECONDS)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
304 if min_overhead < 0.0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
305 raise ValueError('calibration setup did not work')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
306 if max_overhead - min_overhead > 0.1:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
307 raise ValueError(
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
308 'overhead calibration timing range too inaccurate: '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
309 '%r - %r' % (min_overhead, max_overhead))
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
310
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
311 def run(self):
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
312
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
313 """ Run the test in two phases: first calibrate, then
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
314 do the actual test. Be careful to keep the calibration
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
315 timing low w/r to the test timing.
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
316
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
317 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
318 test = self.test
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
319 timer = self.get_timer()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
320
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
321 # Get calibration
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
322 min_overhead = min(self.overhead_times)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
323
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
324 # Test run
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
325 t = timer()
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
326 test()
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
327 t = timer() - t
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
328 if t < MIN_TEST_RUNTIME:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
329 raise ValueError('warp factor too high: '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
330 'test times are < 10ms')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
331 eff_time = t - min_overhead
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
332 if eff_time < 0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
333 raise ValueError('wrong calibration')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
334 self.last_timing = (eff_time, t, min_overhead)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
335 self.times.append(eff_time)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
336
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
337 def calibrate(self):
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
338
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
339 """ Calibrate the test.
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
340
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
341 This method should execute everything that is needed to
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
342 setup and run the test - except for the actual operations
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
343 that you intend to measure. pybench uses this method to
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
344 measure the test implementation overhead.
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
345
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
346 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
347 return
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
348
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
349 def test(self):
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
350
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
351 """ Run the test.
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
352
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
353 The test needs to run self.rounds executing
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
354 self.operations number of operations each.
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
355
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
356 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
357 return
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
358
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
359 def stat(self):
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
360
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
361 """ Return test run statistics as tuple:
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
362
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
363 (minimum run time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
364 average run time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
365 total run time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
366 average time per operation,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
367 minimum overhead time)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
368
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
369 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
370 runs = len(self.times)
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
371 if runs == 0:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
372 return 0.0, 0.0, 0.0, 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
373 min_time = min(self.times)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
374 total_time = reduce(operator.add, self.times, 0.0)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
375 avg_time = total_time / float(runs)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
376 operation_avg = total_time / float(runs
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
377 * self.rounds
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
378 * self.operations)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
379 if self.overhead_times:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
380 min_overhead = min(self.overhead_times)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
381 else:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
382 min_overhead = self.last_timing[2]
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
383 return min_time, avg_time, total_time, operation_avg, min_overhead
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
384
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
385 ### Load Setup
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
386
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
387 # This has to be done after the definition of the Test class, since
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
388 # the Setup module will import subclasses using this class.
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
389
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
390 import Setup
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
391
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
392 ### Benchmark base class
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
393
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
394 class Benchmark:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
395
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
396 # Name of the benchmark
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
397 name = ''
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
398
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
399 # Number of benchmark rounds to run
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
400 rounds = 1
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
401
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
402 # Warp factor use to run the tests
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
403 warp = 1 # Warp factor
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
404
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
405 # Average benchmark round time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
406 roundtime = 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
407
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
408 # Benchmark version number as float x.yy
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
409 version = 2.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
410
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
411 # Produce verbose output ?
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
412 verbose = 0
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
413
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
414 # Dictionary with the machine details
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
415 machine_details = None
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
416
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
417 # Timer used for the benchmark
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
418 timer = TIMER_PLATFORM_DEFAULT
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
419
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
420 def __init__(self, name, verbose=None, timer=None, warp=None,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
421 calibration_runs=None):
38803
70c2efa00007 Whitespace normalization.
Marc-André Lemburg <mal@egenix.com>
parents: 38801
diff changeset
422
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
423 if name:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
424 self.name = name
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
425 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
426 self.name = '%04i-%02i-%02i %02i:%02i:%02i' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
427 (time.localtime(time.time())[:6])
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
428 if verbose is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
429 self.verbose = verbose
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
430 if timer is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
431 self.timer = timer
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
432 if warp is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
433 self.warp = warp
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
434 if calibration_runs is not None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
435 self.calibration_runs = calibration_runs
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
436
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
437 # Init vars
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
438 self.tests = {}
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
439 if _debug:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
440 print 'Getting machine details...'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
441 self.machine_details = get_machine_details()
38803
70c2efa00007 Whitespace normalization.
Marc-André Lemburg <mal@egenix.com>
parents: 38801
diff changeset
442
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
443 # Make .version an instance attribute to have it saved in the
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
444 # Benchmark pickle
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
445 self.version = self.version
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
446
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
447 def get_timer(self):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
448
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
449 """ Return the timer function to use for the test.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
450
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
451 """
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
452 return get_timer(self.timer)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
453
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
454 def compatible(self, other):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
455
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
456 """ Return 1/0 depending on whether the benchmark is
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
457 compatible with the other Benchmark instance or not.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
458
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
459 """
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
460 if self.version != other.version:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
461 return 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
462 if (self.machine_details == other.machine_details and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
463 self.timer != other.timer):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
464 return 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
465 if (self.calibration_runs == 0 and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
466 other.calibration_runs != 0):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
467 return 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
468 if (self.calibration_runs != 0 and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
469 other.calibration_runs == 0):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
470 return 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
471 return 1
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
472
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
473 def load_tests(self, setupmod, limitnames=None):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
474
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
475 # Add tests
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
476 if self.verbose:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
477 print 'Searching for tests ...'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
478 print '--------------------------------------'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
479 for testclass in setupmod.__dict__.values():
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
480 if not hasattr(testclass, 'is_a_test'):
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
481 continue
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
482 name = testclass.__name__
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
483 if name == 'Test':
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
484 continue
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
485 if (limitnames is not None and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
486 limitnames.search(name) is None):
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
487 continue
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
488 self.tests[name] = testclass(
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
489 warp=self.warp,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
490 calibration_runs=self.calibration_runs,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
491 timer=self.timer)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
492 l = self.tests.keys()
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
493 l.sort()
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
494 if self.verbose:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
495 for name in l:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
496 print ' %s' % name
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
497 print '--------------------------------------'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
498 print ' %i tests found' % len(l)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
499 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
500
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
501 def calibrate(self):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
502
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
503 print 'Calibrating tests. Please wait...',
46521
1acd00f2a380 explicitly flush after the ... since there wasn't a newline
Gregory P. Smith <greg@mad-scientist.com>
parents: 45719
diff changeset
504 sys.stdout.flush()
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
505 if self.verbose:
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
506 print
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
507 print
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
508 print 'Test min max'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
509 print '-' * LINE
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
510 tests = self.tests.items()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
511 tests.sort()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
512 for i in range(len(tests)):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
513 name, test = tests[i]
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
514 test.calibrate_test()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
515 if self.verbose:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
516 print '%30s: %6.3fms %6.3fms' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
517 (name,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
518 min(test.overhead_times) * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
519 max(test.overhead_times) * MILLI_SECONDS)
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
520 if self.verbose:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
521 print
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
522 print 'Done with the calibration.'
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
523 else:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
524 print 'done.'
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
525 print
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
526
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
527 def run(self):
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
528
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
529 tests = self.tests.items()
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
530 tests.sort()
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
531 timer = self.get_timer()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
532 print 'Running %i round(s) of the suite at warp factor %i:' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
533 (self.rounds, self.warp)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
534 print
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
535 self.roundtimes = []
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
536 for i in range(self.rounds):
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
537 if self.verbose:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
538 print ' Round %-25i effective absolute overhead' % (i+1)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
539 total_eff_time = 0.0
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
540 for j in range(len(tests)):
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
541 name, test = tests[j]
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
542 if self.verbose:
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
543 print '%30s:' % name,
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
544 test.run()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
545 (eff_time, abs_time, min_overhead) = test.last_timing
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
546 total_eff_time = total_eff_time + eff_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
547 if self.verbose:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
548 print ' %5.0fms %5.0fms %7.3fms' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
549 (eff_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
550 abs_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
551 min_overhead * MILLI_SECONDS)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
552 self.roundtimes.append(total_eff_time)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
553 if self.verbose:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
554 print (' '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
555 ' ------------------------------')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
556 print (' '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
557 ' Totals: %6.0fms' %
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
558 (total_eff_time * MILLI_SECONDS))
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
559 print
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
560 else:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
561 print '* Round %i done in %.3f seconds.' % (i+1,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
562 total_eff_time)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
563 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
564
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
565 def stat(self):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
566
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
567 """ Return benchmark run statistics as tuple:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
568
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
569 (minimum round time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
570 average round time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
571 maximum round time)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
572
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
573 XXX Currently not used, since the benchmark does test
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
574 statistics across all rounds.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
575
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
576 """
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
577 runs = len(self.roundtimes)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
578 if runs == 0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
579 return 0.0, 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
580 min_time = min(self.roundtimes)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
581 total_time = reduce(operator.add, self.roundtimes, 0.0)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
582 avg_time = total_time / float(runs)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
583 max_time = max(self.roundtimes)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
584 return (min_time, avg_time, max_time)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
585
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
586 def print_header(self, title='Benchmark'):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
587
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
588 print '-' * LINE
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
589 print '%s: %s' % (title, self.name)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
590 print '-' * LINE
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
591 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
592 print ' Rounds: %s' % self.rounds
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
593 print ' Warp: %s' % self.warp
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
594 print ' Timer: %s' % self.timer
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
595 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
596 if self.machine_details:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
597 print_machine_details(self.machine_details, indent=' ')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
598 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
599
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
600 def print_benchmark(self, hidenoise=0, limitnames=None):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
601
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
602 print ('Test '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
603 ' minimum average operation overhead')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
604 print '-' * LINE
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
605 tests = self.tests.items()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
606 tests.sort()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
607 total_min_time = 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
608 total_avg_time = 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
609 for name, test in tests:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
610 if (limitnames is not None and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
611 limitnames.search(name) is None):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
612 continue
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
613 (min_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
614 avg_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
615 total_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
616 op_avg,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
617 min_overhead) = test.stat()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
618 total_min_time = total_min_time + min_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
619 total_avg_time = total_avg_time + avg_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
620 print '%30s: %5.0fms %5.0fms %6.2fus %7.3fms' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
621 (name,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
622 min_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
623 avg_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
624 op_avg * MICRO_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
625 min_overhead *MILLI_SECONDS)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
626 print '-' * LINE
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
627 print ('Totals: '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
628 ' %6.0fms %6.0fms' %
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
629 (total_min_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
630 total_avg_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
631 ))
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
632 print
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
633
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
634 def print_comparison(self, compare_to, hidenoise=0, limitnames=None):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
635
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
636 # Check benchmark versions
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
637 if compare_to.version != self.version:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
638 print ('* Benchmark versions differ: '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
639 'cannot compare this benchmark to "%s" !' %
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
640 compare_to.name)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
641 print
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
642 self.print_benchmark(hidenoise=hidenoise,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
643 limitnames=limitnames)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
644 return
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
645
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
646 # Print header
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
647 compare_to.print_header('Comparing with')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
648 print ('Test '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
649 ' minimum run-time average run-time')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
650 print (' '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
651 ' this other diff this other diff')
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
652 print '-' * LINE
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
653
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
654 # Print test comparisons
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
655 tests = self.tests.items()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
656 tests.sort()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
657 total_min_time = other_total_min_time = 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
658 total_avg_time = other_total_avg_time = 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
659 benchmarks_compatible = self.compatible(compare_to)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
660 tests_compatible = 1
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
661 for name, test in tests:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
662 if (limitnames is not None and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
663 limitnames.search(name) is None):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
664 continue
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
665 (min_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
666 avg_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
667 total_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
668 op_avg,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
669 min_overhead) = test.stat()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
670 total_min_time = total_min_time + min_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
671 total_avg_time = total_avg_time + avg_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
672 try:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
673 other = compare_to.tests[name]
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
674 except KeyError:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
675 other = None
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
676 if other is None:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
677 # Other benchmark doesn't include the given test
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
678 min_diff, avg_diff = 'n/a', 'n/a'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
679 other_min_time = 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
680 other_avg_time = 0.0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
681 tests_compatible = 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
682 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
683 (other_min_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
684 other_avg_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
685 other_total_time,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
686 other_op_avg,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
687 other_min_overhead) = other.stat()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
688 other_total_min_time = other_total_min_time + other_min_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
689 other_total_avg_time = other_total_avg_time + other_avg_time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
690 if (benchmarks_compatible and
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
691 test.compatible(other)):
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
692 # Both benchmark and tests are comparible
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
693 min_diff = ((min_time * self.warp) /
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
694 (other_min_time * other.warp) - 1.0)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
695 avg_diff = ((avg_time * self.warp) /
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
696 (other_avg_time * other.warp) - 1.0)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
697 if hidenoise and abs(min_diff) < 10.0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
698 min_diff = ''
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
699 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
700 min_diff = '%+5.1f%%' % (min_diff * PERCENT)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
701 if hidenoise and abs(avg_diff) < 10.0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
702 avg_diff = ''
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
703 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
704 avg_diff = '%+5.1f%%' % (avg_diff * PERCENT)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
705 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
706 # Benchmark or tests are not comparible
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
707 min_diff, avg_diff = 'n/a', 'n/a'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
708 tests_compatible = 0
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
709 print '%30s: %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
710 (name,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
711 min_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
712 other_min_time * MILLI_SECONDS * compare_to.warp / self.warp,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
713 min_diff,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
714 avg_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
715 other_avg_time * MILLI_SECONDS * compare_to.warp / self.warp,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
716 avg_diff)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
717 print '-' * LINE
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
718
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
719 # Summarise test results
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
720 if not benchmarks_compatible or not tests_compatible:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
721 min_diff, avg_diff = 'n/a', 'n/a'
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
722 else:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
723 if other_total_min_time != 0.0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
724 min_diff = '%+5.1f%%' % (
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
725 ((total_min_time * self.warp) /
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
726 (other_total_min_time * compare_to.warp) - 1.0) * PERCENT)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
727 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
728 min_diff = 'n/a'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
729 if other_total_avg_time != 0.0:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
730 avg_diff = '%+5.1f%%' % (
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
731 ((total_avg_time * self.warp) /
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
732 (other_total_avg_time * compare_to.warp) - 1.0) * PERCENT)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
733 else:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
734 avg_diff = 'n/a'
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
735 print ('Totals: '
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
736 ' %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' %
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
737 (total_min_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
738 (other_total_min_time * compare_to.warp/self.warp
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
739 * MILLI_SECONDS),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
740 min_diff,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
741 total_avg_time * MILLI_SECONDS,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
742 (other_total_avg_time * compare_to.warp/self.warp
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
743 * MILLI_SECONDS),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
744 avg_diff
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
745 ))
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
746 print
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
747 print '(this=%s, other=%s)' % (self.name,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
748 compare_to.name)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
749 print
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
750
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
751 class PyBenchCmdline(Application):
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
752
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
753 header = ("PYBENCH - a benchmark test suite for Python "
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
754 "interpreters/compilers.")
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
755
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
756 version = __version__
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
757
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
758 debug = _debug
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
759
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
760 options = [ArgumentOption('-n',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
761 'number of rounds',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
762 Setup.Number_of_rounds),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
763 ArgumentOption('-f',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
764 'save benchmark to file arg',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
765 ''),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
766 ArgumentOption('-c',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
767 'compare benchmark with the one in file arg',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
768 ''),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
769 ArgumentOption('-s',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
770 'show benchmark in file arg, then exit',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
771 ''),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
772 ArgumentOption('-w',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
773 'set warp factor to arg',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
774 Setup.Warp_factor),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
775 ArgumentOption('-t',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
776 'run only tests with names matching arg',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
777 ''),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
778 ArgumentOption('-C',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
779 'set the number of calibration runs to arg',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
780 CALIBRATION_RUNS),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
781 SwitchOption('-d',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
782 'hide noise in comparisons',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
783 0),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
784 SwitchOption('-v',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
785 'verbose output (not recommended)',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
786 0),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
787 SwitchOption('--with-gc',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
788 'enable garbage collection',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
789 0),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
790 SwitchOption('--with-syscheck',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
791 'use default sys check interval',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
792 0),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
793 ArgumentOption('--timer',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
794 'use given timer',
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
795 TIMER_PLATFORM_DEFAULT),
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
796 ]
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
797
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
798 about = """\
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
799 The normal operation is to run the suite and display the
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
800 results. Use -f to save them for later reuse or comparisons.
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
802 Available timers:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
803
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
804 time.time
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
805 time.clock
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
806 systimes.processtime
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
807
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
808 Examples:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
809
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
810 python2.1 pybench.py -f p21.pybench
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
811 python2.5 pybench.py -f p25.pybench
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
812 python pybench.py -s p25.pybench -c p21.pybench
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
813 """
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
814 copyright = __copyright__
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
815
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
816 def main(self):
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
817
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
818 rounds = self.values['-n']
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
819 reportfile = self.values['-f']
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
820 show_bench = self.values['-s']
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
821 compare_to = self.values['-c']
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
822 hidenoise = self.values['-d']
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
823 warp = int(self.values['-w'])
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
824 withgc = self.values['--with-gc']
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
825 limitnames = self.values['-t']
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
826 if limitnames:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
827 if _debug:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
828 print '* limiting test names to one with substring "%s"' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
829 limitnames
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
830 limitnames = re.compile(limitnames, re.I)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
831 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
832 limitnames = None
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
833 verbose = self.verbose
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
834 withsyscheck = self.values['--with-syscheck']
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
835 calibration_runs = self.values['-C']
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
836 timer = self.values['--timer']
38413
8e2dc3e41801 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 38392
diff changeset
837
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
838 print '-' * LINE
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
839 print 'PYBENCH %s' % __version__
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
840 print '-' * LINE
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
841 print '* using %s %s' % (
45719
5b4239c1f8f8 Well that was dumb. platform.python_implementation returns a function, not a
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 45718
diff changeset
842 getattr(platform, 'python_implementation', lambda:'Python')(),
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
843 string.join(string.split(sys.version), ' '))
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
844
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
845 # Switch off garbage collection
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
846 if not withgc:
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
847 try:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
848 import gc
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
849 except ImportError:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
850 print '* Python version doesn\'t support garbage collection'
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
851 else:
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
852 try:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
853 gc.disable()
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
854 except NotImplementedError:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
855 print '* Python version doesn\'t support gc.disable'
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
856 else:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
857 print '* disabled garbage collection'
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
858
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
859 # "Disable" sys check interval
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
860 if not withsyscheck:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
861 # Too bad the check interval uses an int instead of a long...
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
862 value = 2147483647
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
863 try:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
864 sys.setcheckinterval(value)
40623
ca1b40cc6b74 Jython doesn't have sys.setcheckinterval() - ignore it in that case.
Marc-André Lemburg <mal@egenix.com>
parents: 40621
diff changeset
865 except (AttributeError, NotImplementedError):
40621
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
866 print '* Python version doesn\'t support sys.setcheckinterval'
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
867 else:
73b93dc5e440 Add Python implementation to the machine details.
Marc-André Lemburg <mal@egenix.com>
parents: 39704
diff changeset
868 print '* system check interval set to maximum: %s' % value
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
869
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
870 if timer == TIMER_SYSTIMES_PROCESSTIME:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
871 import systimes
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
872 print '* using timer: systimes.processtime (%s)' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
873 systimes.SYSTIMES_IMPLEMENTATION
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
874 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
875 print '* using timer: %s' % timer
38375
52d1399e1c6d Add -t option to allow easy test selection.
Steve Holden <steve@holdenweb.com>
parents: 37903
diff changeset
876
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
877 print
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
878
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
879 if compare_to:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
880 try:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
881 f = open(compare_to,'rb')
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
882 bench = pickle.load(f)
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
883 bench.name = compare_to
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
884 f.close()
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
885 compare_to = bench
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
886 except IOError, reason:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
887 print '* Error opening/reading file %s: %s' % (
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
888 repr(compare_to),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
889 reason)
37903
56089faba056 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 37857
diff changeset
890 compare_to = None
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
891
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
892 if show_bench:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
893 try:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
894 f = open(show_bench,'rb')
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
895 bench = pickle.load(f)
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
896 bench.name = show_bench
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
897 f.close()
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
898 bench.print_header()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
899 if compare_to:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
900 bench.print_comparison(compare_to,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
901 hidenoise=hidenoise,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
902 limitnames=limitnames)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
903 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
904 bench.print_benchmark(hidenoise=hidenoise,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
905 limitnames=limitnames)
39704
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
906 except IOError, reason:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
907 print '* Error opening/reading file %s: %s' % (
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
908 repr(show_bench),
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
909 reason)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
910 print
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
911 return
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
912
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
913 if reportfile:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
914 print 'Creating benchmark: %s (rounds=%i, warp=%i)' % \
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
915 (reportfile, rounds, warp)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
916 print
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
917
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
918 # Create benchmark object
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
919 bench = Benchmark(reportfile,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
920 verbose=verbose,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
921 timer=timer,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
922 warp=warp,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
923 calibration_runs=calibration_runs)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
924 bench.rounds = rounds
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
925 bench.load_tests(Setup, limitnames=limitnames)
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
926 try:
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
927 bench.calibrate()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
928 bench.run()
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
929 except KeyboardInterrupt:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
930 print
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
931 print '*** KeyboardInterrupt -- Aborting'
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
932 print
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
933 return
38801
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
934 bench.print_header()
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
935 if compare_to:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
936 bench.print_comparison(compare_to,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
937 hidenoise=hidenoise,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
938 limitnames=limitnames)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
939 else:
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
940 bench.print_benchmark(hidenoise=hidenoise,
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
941 limitnames=limitnames)
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
942
2167105123e4 Updated to pybench 2.0.
Marc-André Lemburg <mal@egenix.com>
parents: 38415
diff changeset
943 # Ring bell
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
944 sys.stderr.write('\007')
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
945
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
946 if reportfile:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
947 try:
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
948 f = open(reportfile,'wb')
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
949 bench.name = reportfile
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
950 pickle.dump(bench,f)
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
951 f.close()
39704
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
952 except IOError, reason:
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
953 print '* Error opening/writing reportfile'
39704
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
954 except IOError, reason:
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
955 print '* Error opening/writing reportfile %s: %s' % (
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
956 reportfile,
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
957 reason)
754a729e97af Fix a buglet in the error reporting (SF bug report #1546372).
Marc-André Lemburg <mal@egenix.com>
parents: 38803
diff changeset
958 print
37857
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
959
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
960 if __name__ == '__main__':
a4d5cefc2de4 Adding pybench 1.3 to the Tools/ directory.
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
961 PyBenchCmdline()