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 | |
| 8 | |
| 9 | if sys.argv[1:]: |
| 10 | logfile = sys.argv[1] |
| 11 | cleanup = 0 |
| 12 | else: |
| 13 | import tempfile |
| 14 | logfile = tempfile.mktemp() |
| 15 | cleanup = 1 |
| 16 | |
| 17 | |
| 18 | p = hotshot.Profile(logfile) |
| 19 | benchtime, stones = p.runcall(test.pystone.pystones) |
| 20 | p.close() |
| 21 | |
| 22 | print "Pystone(%s) time for %d passes = %g" % \ |
| 23 | (test.pystone.__version__, test.pystone.LOOPS, benchtime) |
| 24 | print "This machine benchmarks at %g pystones/second" % stones |
| 25 | |
| 26 | stats = hotshot.stats.load(logfile) |
| 27 | if cleanup: |
| 28 | os.unlink(logfile) |
| 29 | stats.strip_dirs() |
| 30 | stats.sort_stats('time', 'calls') |
| 31 | try: |
| 32 | stats.print_stats(20) |
| 33 | except IOError, e: |
| 34 | if e.errno != errno.EPIPE: |
| 35 | raise |