stones.py 767 B

123456789101112131415161718192021222324252627282930
  1. import errno
  2. import hotshot
  3. import hotshot.stats
  4. import sys
  5. import test.pystone
  6. def main(logfile):
  7. p = hotshot.Profile(logfile)
  8. benchtime, stones = p.runcall(test.pystone.pystones)
  9. p.close()
  10. print "Pystone(%s) time for %d passes = %g" % \
  11. (test.pystone.__version__, test.pystone.LOOPS, benchtime)
  12. print "This machine benchmarks at %g pystones/second" % stones
  13. stats = hotshot.stats.load(logfile)
  14. stats.strip_dirs()
  15. stats.sort_stats('time', 'calls')
  16. try:
  17. stats.print_stats(20)
  18. except IOError, e:
  19. if e.errno != errno.EPIPE:
  20. raise
  21. if __name__ == '__main__':
  22. if sys.argv[1:]:
  23. main(sys.argv[1])
  24. else:
  25. import tempfile
  26. main(tempfile.NamedTemporaryFile().name)