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