[Python-checkins] benchmarks: Fix gcbench for Python 3

antoine.pitrou python-checkins at python.org
Fri Dec 16 00:21:47 CET 2011


http://hg.python.org/benchmarks/rev/3f1cef15cf22
changeset: 154:3f1cef15cf22
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri Dec 16 00:21:23 2011 +0100
summary:
 Fix gcbench for Python 3
files:
 performance/gcbench.py | 31 ++++++++++++++++-------------
 1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/performance/gcbench.py b/performance/gcbench.py
--- a/performance/gcbench.py
+++ b/performance/gcbench.py
@@ -43,6 +43,9 @@
 # - No attempt to measure variation with object size
 # - Results are sensitive to locking cost, but we dont
 # check for proper locking
+
+from __future__ import print_function
+
 import os, time
 
 USAGE = """gcbench [num_repetitions] [--depths=N,N,N..] [--threads=N]"""
@@ -67,7 +70,7 @@
 
 def num_iters(i):
 "Number of iterations to use for a given tree depth"
- return 2 * tree_size(kStretchTreeDepth) / tree_size(i);
+ return 2 * tree_size(kStretchTreeDepth) // tree_size(i);
 
 def populate(depth, node):
 "Build tree top down, assigning to older objects."
@@ -93,20 +96,20 @@
 
 def time_construction(depth):
 niters = num_iters(depth)
- print "Creating %d trees of depth %d" % (niters, depth)
+ print("Creating %d trees of depth %d" % (niters, depth))
 t_start = time.time()
 for i in range(niters):
 temp_tree = Node()
 populate(depth, temp_tree)
 temp_tree = None
 t_finish = time.time()
- print "\tTop down constrution took %f ms" % ((t_finish-t_start)*1000.)
+ print("\tTop down constrution took %f ms" % ((t_finish-t_start)*1000.))
 t_start = time.time()
 for i in range(niters):
 temp_tree = make_tree(depth)
 temp_tree = None
 t_finish = time.time()
- print "\tBottom up constrution took %f ms" % ((t_finish-t_start)*1000.)
+ print("\tBottom up constrution took %f ms" % ((t_finish-t_start)*1000.))
 
 DEFAULT_DEPTHS = range(kMinTreeDepth, kMaxTreeDepth+1, 2)
 
@@ -117,30 +120,30 @@
 def time_parallel_constructions(depths, nthreads):
 import threading
 threadlist = []
- print "Starting %d parallel threads..." % (nthreads,)
+ print("Starting %d parallel threads..." % (nthreads,))
 for n in range(nthreads):
 t = threading.Thread(target=time_constructions, args=(depths,))
 t.start()
 threadlist.append(t)
 for t in threadlist:
 t.join()
- print "All %d threads finished" % (nthreads,)
+ print("All %d threads finished" % (nthreads,))
 
 def main(depths=DEFAULT_DEPTHS, threads=0):
- print "Garbage Collector Test"
- print " Stretching memory with a binary tree of depth %d" % kStretchTreeDepth
+ print("Garbage Collector Test")
+ print(" Stretching memory with a binary tree of depth %d" % kStretchTreeDepth)
 print_diagnostics()
 t_start = time.time()
 temp_tree = make_tree(kStretchTreeDepth)
 temp_tree = None
 
 # Create a long lived object
- print " Creating a long-lived binary tree of depth %d" % kLongLivedTreeDepth
+ print(" Creating a long-lived binary tree of depth %d" % kLongLivedTreeDepth)
 long_lived_tree = Node()
 populate(kLongLivedTreeDepth, long_lived_tree)
 
 # Create long-lived array, filling half of it
- print " Creating a long-lived array of %d doubles" % kArraySize
+ print(" Creating a long-lived array of %d doubles" % kArraySize)
 array = [0.0] * kArraySize
 i = 1
 while i < kArraySize/2:
@@ -158,15 +161,15 @@
 
 t_finish = time.time()
 print_diagnostics()
- print "Completed in %f ms." % ((t_finish-t_start)*1000.)
+ print("Completed in %f ms." % ((t_finish-t_start)*1000.))
 
 class Failed(Exception):
 pass
 
 
 def argerror():
- print "Usage:"
- print " ", USAGE
+ print("Usage:")
+ print(" ", USAGE)
 return 2
 
 def entry_point(argv):
@@ -177,7 +180,7 @@
 if arg.startswith('--threads='):
 arg = arg[len('--threads='):]
 if not ENABLE_THREADS:
- print "threads disabled (they cannot be translated)"
+ print("threads disabled (they cannot be translated)")
 return 1
 try:
 threads = int(arg)
-- 
Repository URL: http://hg.python.org/benchmarks


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /