Fred Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 1 | import errno |
| 2 | import hotshot |
| 3 | import hotshot.stats |
| 4 | import os |
| 5 | import sys |
| 6 | import test.pystone |
| 7 | |
Ka-Ping Yee | e9638cc | 2003-03-28 16:28:48 +0000 | [diff] [blame] | 8 | def main(logfile): |
| 9 | p = hotshot.Profile(logfile) |
| 10 | benchtime, stones = p.runcall(test.pystone.pystones) |
| 11 | p.close() |
Fred Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 13 | 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 Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 16 | |
Ka-Ping Yee | e9638cc | 2003-03-28 16:28:48 +0000 | [diff] [blame] | 17 | stats = hotshot.stats.load(logfile) |
| 18 | stats.strip_dirs() |
| 19 | stats.sort_stats('time', 'calls') |
| 20 | try: |
| 21 | stats.print_stats(20) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 22 | except IOError as e: |
Ka-Ping Yee | e9638cc | 2003-03-28 16:28:48 +0000 | [diff] [blame] | 23 | if e.errno != errno.EPIPE: |
| 24 | raise |
Fred Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 25 | |
Ka-Ping Yee | e9638cc | 2003-03-28 16:28:48 +0000 | [diff] [blame] | 26 | if __name__ == '__main__': |
| 27 | if sys.argv[1:]: |
| 28 | main(sys.argv[1]) |
| 29 | else: |
| 30 | import tempfile |
| 31 | main(tempfile.NamedTemporaryFile().name) |