3
# (C) Copyright IBM Corporation 2004
6
# Permission is hereby granted, free of charge, to any person obtaining a
7
# copy of this software and associated documentation files (the "Software"),
8
# to deal in the Software without restriction, including without limitation
9
# on the rights to use, copy, modify, merge, publish, distribute, sub
10
# license, and/or sell copies of the Software, and to permit persons to whom
11
# the Software is furnished to do so, subject to the following conditions:
13
# The above copyright notice and this permission notice (including the next
14
# paragraph) shall be included in all copies or substantial portions of the
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20
# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26
# Ian Romanick <idr@us.ibm.com>
29
# This script is used to run api_speed against several different libGL
30
# libraries and compare the results. See the show_usage function for more
31
# details on how to use it.
34
import re, os, sys, getopt
37
def process_file(self, f):
41
for line in f.readlines():
42
m = re.match("(\d+) calls to (.{20}) required (\d+) cycles.", line)
44
if self.iterations != -1 and int(m.group(1)) != self.iterations:
47
# This could be done with lstrip, but the version of
48
# the Python library on my system doesn't have it.
49
# The installed version of Python is quite old. :(
53
for i in range(len(temp)):
55
function_name = temp[i:]
58
if function_name == None:
61
self.cycles[ function_name ] = int(m.group(3))
62
self.iterations = int(m.group(1))
65
def show_results(self):
66
for name in self.cycles:
67
print "%s -> %f" % (name, float(self.cycles[name]) / self.iterations)
70
def compare_results(self, other):
71
for name in self.cycles:
72
if other.cycles.has_key(name):
73
a = float(self.cycles[name]) / float(self.iterations)
74
b = float(other.cycles[name]) / float(other.iterations)
75
if abs( a ) < 0.000001:
76
print "a = %f, b = %f" % (a, b)
78
p = (100.0 * b / a) - 100.0
79
print "%- 20s %7.2f - %7.2f = % -6.2f (%+.1f%%)" % (name, a, b, a - b, p)
83
def make_execution_string(lib, iterations):
85
return "./api_speed %u" % (iterations)
87
return "LD_PRELOAD=%s ./api_speed %u" % (lib, iterations)
91
print """Usage: %s [-i iterations] {library ...}
93
The full path to one or more libGL libraries (including the full name of the
94
library) can be included on the command-line. Each library will be tested,
95
and the results compared. The first library listed will be used as the
96
"base line" for all comparisons.""" % (sys.argv[0])
100
if __name__ == '__main__':
102
(args, trail) = getopt.getopt(sys.argv[1:], "i:")
108
for (arg,val) in args:
110
iterations = int(val)
115
# If no libraries were specifically named, just run the test against
116
# the default system libGL.
126
s = make_execution_string( lib, iterations )
128
r.process_file( os.popen(s) )
130
result_array.append(r)
133
# If the test was only run against one library, just show the results
134
# of the test run. Otherwise, compare each successive run against
137
if len( result_array ) == 1:
138
result_array[0].show_results()
140
for i in range(1, len( result_array )):
141
print "%s vs. %s" % (names[0], names[i])
142
result_array[0].compare_results( result_array[i] )