blob: cd4c51d483678ae189a35514c1fa48ac11c62579 [file] [log] [blame]
Fred Drake0d7e68a2002-07-18 19:47:05 +00001import errno
2import hotshot
3import hotshot.stats
4import os
5import sys
6import test.pystone
7
Ka-Ping Yeee9638cc2003-03-28 16:28:48 +00008def main(logfile):
9 p = hotshot.Profile(logfile)
10 benchtime, stones = p.runcall(test.pystone.pystones)
11 p.close()
Fred Drake0d7e68a2002-07-18 19:47:05 +000012
Ka-Ping Yeee9638cc2003-03-28 16:28:48 +000013 print "Pystone(%s) time for %d passes = %g" % \
14 (test.pystone.__version__, test.pystone.LOOPS, benchtime)
15 print "This machine benchmarks at %g pystones/second" % stones
Fred Drake0d7e68a2002-07-18 19:47:05 +000016
Ka-Ping Yeee9638cc2003-03-28 16:28:48 +000017 stats = hotshot.stats.load(logfile)
18 stats.strip_dirs()
19 stats.sort_stats('time', 'calls')
20 try:
21 stats.print_stats(20)
22 except IOError, e:
23 if e.errno != errno.EPIPE:
24 raise
Fred Drake0d7e68a2002-07-18 19:47:05 +000025
Ka-Ping Yeee9638cc2003-03-28 16:28:48 +000026if __name__ == '__main__':
27 if sys.argv[1:]:
28 main(sys.argv[1])
29 else:
30 import tempfile
31 main(tempfile.NamedTemporaryFile().name)