[Python-checkins] r53414 - python/trunk/Tools/pybench/pybench.py

marc-andre.lemburg python-checkins at python.org
Sat Jan 13 23:59:38 CET 2007


Author: marc-andre.lemburg
Date: Sat Jan 13 23:59:36 2007
New Revision: 53414

Modified:
   python/trunk/Tools/pybench/pybench.py
Log:
Add Python implementation to the machine details.

Pretty-print the Python version used for running PyBench.

Let the user know when calibration has finished.

[ 1563844 ] pybench support for IronPython:

Simplify Unicode version detection.

Make garbage collection and check interval settings optional if
the Python implementation doesn't support thess (e.g. IronPython).



Modified: python/trunk/Tools/pybench/pybench.py
==============================================================================
--- python/trunk/Tools/pybench/pybench.py	(original)
+++ python/trunk/Tools/pybench/pybench.py	Sat Jan 13 23:59:36 2007
@@ -34,7 +34,7 @@
 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
 """
 
-import sys, time, operator, string
+import sys, time, operator, string, platform
 from CommandLine import *
 
 try:
@@ -102,27 +102,26 @@
 
 def get_machine_details():
 
-    import platform
     if _debug:
         print 'Getting machine details...'
     buildno, builddate = platform.python_build()
     python = platform.python_version()
-    if python > '2.0':
-        try:
-            unichr(100000)
-        except ValueError:
-            # UCS2 build (standard)
-            unicode = 'UCS2'
-        else:
-            # UCS4 build (most recent Linux distros)
-            unicode = 'UCS4'
-    else:
+    try:
+        unichr(100000)
+    except ValueError:
+        # UCS2 build (standard)
+        unicode = 'UCS2'
+    except NameError:
         unicode = None
+    else:
+        # UCS4 build (most recent Linux distros)
+        unicode = 'UCS4'
     bits, linkage = platform.architecture()
     return {
         'platform': platform.platform(),
         'processor': platform.processor(),
         'executable': sys.executable,
+        'implementation': platform.python_implementation(),
         'python': platform.python_version(),
         'compiler': platform.python_compiler(),
         'buildno': buildno,
@@ -134,17 +133,18 @@
 def print_machine_details(d, indent=''):
 
     l = ['Machine Details:',
-         '   Platform ID:  %s' % d.get('platform', 'n/a'),
-         '   Processor:    %s' % d.get('processor', 'n/a'),
+         '   Platform ID:    %s' % d.get('platform', 'n/a'),
+         '   Processor:      %s' % d.get('processor', 'n/a'),
          '',
          'Python:',
-         '   Executable:   %s' % d.get('executable', 'n/a'),
-         '   Version:      %s' % d.get('python', 'n/a'),
-         '   Compiler:     %s' % d.get('compiler', 'n/a'),
-         '   Bits:         %s' % d.get('bits', 'n/a'),
-         '   Build:        %s (#%s)' % (d.get('builddate', 'n/a'),
-                                        d.get('buildno', 'n/a')),
-         '   Unicode:      %s' % d.get('unicode', 'n/a'),
+         '   Implementation: %s' % d.get('implementation', 'n/a'),
+         '   Executable:     %s' % d.get('executable', 'n/a'),
+         '   Version:        %s' % d.get('python', 'n/a'),
+         '   Compiler:       %s' % d.get('compiler', 'n/a'),
+         '   Bits:           %s' % d.get('bits', 'n/a'),
+         '   Build:          %s (#%s)' % (d.get('builddate', 'n/a'),
+                                          d.get('buildno', 'n/a')),
+         '   Unicode:        %s' % d.get('unicode', 'n/a'),
          ]
     print indent + string.join(l, '\n' + indent) + '\n'
 
@@ -499,9 +499,10 @@
 
     def calibrate(self):
 
-        print 'Calibrating tests. Please wait...'
+        print 'Calibrating tests. Please wait...',
         if self.verbose:
             print
+            print
             print 'Test                              min      max'
             print '-' * LINE
         tests = self.tests.items()
@@ -514,6 +515,11 @@
                       (name,
                        min(test.overhead_times) * MILLI_SECONDS,
                        max(test.overhead_times) * MILLI_SECONDS)
+        if self.verbose:
+            print
+            print 'Done with the calibration.'
+        else:
+            print 'done.'
         print
 
     def run(self):
@@ -830,7 +836,9 @@
         print '-' * LINE
         print 'PYBENCH %s' % __version__
         print '-' * LINE
-        print '* using Python %s' % (string.split(sys.version)[0])
+        print '* using %s %s' % (
+            platform.python_implementation(),
+            string.join(string.split(sys.version), ' '))
 
         # Switch off garbage collection
         if not withgc:
@@ -839,15 +847,23 @@
             except ImportError:
                 print '* Python version doesn\'t support garbage collection'
             else:
-                gc.disable()
-                print '* disabled garbage collection'
+                try:
+                    gc.disable()
+                except NotImplementedError:
+                    print '* Python version doesn\'t support gc.disable'
+                else:
+                    print '* disabled garbage collection'
 
         # "Disable" sys check interval
         if not withsyscheck:
             # Too bad the check interval uses an int instead of a long...
             value = 2147483647
-            sys.setcheckinterval(value)
-            print '* system check interval set to maximum: %s' % value
+            try:
+                sys.setcheckinterval(value)
+            except NotImplementedError:
+                print '* Python version doesn\'t support sys.setcheckinterval'
+            else:
+                print '* system check interval set to maximum: %s' % value
 
         if timer == TIMER_SYSTIMES_PROCESSTIME:
             import systimes


More information about the Python-checkins mailing list