diff options
Diffstat (limited to 'test/grabberperf.py')
-rwxr-xr-x[-rw-r--r--] | test/grabberperf.py | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/test/grabberperf.py b/test/grabberperf.py index 820da2c..31771ae 100644..100755 --- a/test/grabberperf.py +++ b/test/grabberperf.py @@ -11,14 +11,16 @@ # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., -# 59 Temple Place, Suite 330, +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, # Boston, MA 02111-1307 USA # This file is part of urlgrabber, a high-level cross-protocol url-grabber # Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko +from __future__ import print_function + import sys import os from os.path import dirname, join as joinpath @@ -46,16 +48,16 @@ def main(): # remove temp files os.unlink(tempsrc) os.unlink(tempdst) - + def setuptemp(size): - if DEBUG: print 'writing %d KB to temporary file (%s).' % (size / 1024, tempsrc) + if DEBUG: print('writing %d KB to temporary file (%s).' % (size / 1024, tempsrc)) file = open(tempsrc, 'w', 1024) chars = '0123456789' for i in range(size): file.write(chars[i % 10]) file.flush() file.close() - + def speedtest(size): setuptemp(size) full_times = [] @@ -65,12 +67,12 @@ def speedtest(size): try: from urlgrabber.progress import text_progress_meter - except ImportError, e: + except ImportError as e: tpm = None - print 'not using progress meter' + print('not using progress meter') else: tpm = text_progress_meter(fo=open('/dev/null', 'w')) - + # to address concerns that the overhead from the progress meter # and throttling slow things down, we do this little test. # @@ -81,17 +83,17 @@ def speedtest(size): # note: it _is_ even slower to direct the progress meter to a real # tty or file, but I'm just interested in the overhead from _this_ # module. - + # get it nicely cached before we start comparing - if DEBUG: print 'pre-caching' + if DEBUG: print('pre-caching') for i in range(100): urlgrab(tempsrc, tempdst, copy_local=1, throttle=None, proxies=proxies) - - if DEBUG: print 'running speed test.' + + if DEBUG: print('running speed test.') reps = 500 for i in range(reps): - if DEBUG: - print '\r%4i/%-4i' % (i+1, reps), + if DEBUG: + print('\r%4i/%-4i' % (i+1, reps), end=' ') sys.stdout.flush() t = time.time() urlgrab(tempsrc, tempdst, @@ -108,7 +110,7 @@ def speedtest(size): t = time.time() in_fo = open(tempsrc) out_fo = open(tempdst, 'wb') - while 1: + while True: s = in_fo.read(1024 * 8) if not s: break out_fo.write(s) @@ -116,9 +118,9 @@ def speedtest(size): out_fo.close() none_times.append(1000 * (time.time() - t)) - if DEBUG: print '\r' + if DEBUG: print('\r') - print "%d KB Results:" % (size / 1024) + print("%d KB Results:" % (size / 1024)) print_result('full', full_times) print_result('raw', raw_times) print_result('none', none_times) @@ -131,7 +133,7 @@ def print_result(label, result_list): for i in result_list: mean += i mean = mean/len(result_list) median = result_list[int(len(result_list)/2)] - print format % (label, mean, median, result_list[0], result_list[-1]) + print(format % (label, mean, median, result_list[0], result_list[-1])) if __name__ == '__main__': main() |