[Python-checkins] python/dist/src/Lib/hotshot stones.py,1.2,1.3

ping@users.sourceforge.net ping@users.sourceforge.net
Fri, 28 Mar 2003 08:28:53 -0800


Update of /cvsroot/python/python/dist/src/Lib/hotshot
In directory sc8-pr-cvs1:/tmp/cvs-serv11288/hotshot

Modified Files:
	stones.py 
Log Message:
Move testing code into "if __name__ == '__main__'" so it's not run on import.


Index: stones.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/hotshot/stones.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** stones.py	9 Aug 2002 16:37:34 -0000	1.2
--- stones.py	28 Mar 2003 16:28:48 -0000	1.3
***************
*** 6,31 ****
  import test.pystone
  
  
! if sys.argv[1:]:
!     logfile = sys.argv[1]
! else:
!     import tempfile
!     logf = tempfile.NamedTemporaryFile()
!     logfile = logf.name
! 
! p = hotshot.Profile(logfile)
! benchtime, stones = p.runcall(test.pystone.pystones)
! p.close()
  
! print "Pystone(%s) time for %d passes = %g" % \
!       (test.pystone.__version__, test.pystone.LOOPS, benchtime)
! print "This machine benchmarks at %g pystones/second" % stones
  
! stats = hotshot.stats.load(logfile)
! stats.strip_dirs()
! stats.sort_stats('time', 'calls')
! try:
!     stats.print_stats(20)
! except IOError, e:
!     if e.errno != errno.EPIPE:
!         raise
--- 6,31 ----
  import test.pystone
  
+ def main(logfile):
+     p = hotshot.Profile(logfile)
+     benchtime, stones = p.runcall(test.pystone.pystones)
+     p.close()
  
!     print "Pystone(%s) time for %d passes = %g" % \
!           (test.pystone.__version__, test.pystone.LOOPS, benchtime)
!     print "This machine benchmarks at %g pystones/second" % stones
  
!     stats = hotshot.stats.load(logfile)
!     stats.strip_dirs()
!     stats.sort_stats('time', 'calls')
!     try:
!         stats.print_stats(20)
!     except IOError, e:
!         if e.errno != errno.EPIPE:
!             raise
  
! if __name__ == '__main__':
!     if sys.argv[1:]:
!         main(sys.argv[1])
!     else:
!         import tempfile
!         main(tempfile.NamedTemporaryFile().name)