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] |
Fred Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 11 | else: |
| 12 | import tempfile |
Guido van Rossum | 3b0a329 | 2002-08-09 16:38:32 +0000 | [diff] [blame^] | 13 | logf = tempfile.NamedTemporaryFile() |
| 14 | logfile = logf.name |
Fred Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 15 | |
| 16 | p = hotshot.Profile(logfile) |
| 17 | benchtime, stones = p.runcall(test.pystone.pystones) |
| 18 | p.close() |
| 19 | |
| 20 | print "Pystone(%s) time for %d passes = %g" % \ |
| 21 | (test.pystone.__version__, test.pystone.LOOPS, benchtime) |
| 22 | print "This machine benchmarks at %g pystones/second" % stones |
| 23 | |
| 24 | stats = hotshot.stats.load(logfile) |
Fred Drake | 0d7e68a | 2002-07-18 19:47:05 +0000 | [diff] [blame] | 25 | stats.strip_dirs() |
| 26 | stats.sort_stats('time', 'calls') |
| 27 | try: |
| 28 | stats.print_stats(20) |
| 29 | except IOError, e: |
| 30 | if e.errno != errno.EPIPE: |
| 31 | raise |