[Python-checkins] r68078 - sandbox/trunk/iobench/iobench.py
antoine.pitrou
python-checkins at python.org
Tue Dec 30 20:03:59 CET 2008
Author: antoine.pitrou
Date: Tue Dec 30 20:03:59 2008
New Revision: 68078
Log:
add two tests and change wording a bit
Modified:
sandbox/trunk/iobench/iobench.py
Modified: sandbox/trunk/iobench/iobench.py
==============================================================================
--- sandbox/trunk/iobench/iobench.py (original)
+++ sandbox/trunk/iobench/iobench.py Tue Dec 30 20:03:59 2008
@@ -47,7 +47,7 @@
@with_open_mode("r")
@with_sizes("medium")
def read_bytewise(f):
- """ read one byte/char at a time """
+ """ read one unit at a time """
f.seek(0)
while f.read(1):
pass
@@ -55,7 +55,7 @@
@with_open_mode("r")
@with_sizes("medium")
def read_small_chunks(f):
- """ read 20 bytes/chars at a time """
+ """ read 20 units at a time """
f.seek(0)
while f.read(20):
pass
@@ -63,7 +63,7 @@
@with_open_mode("r")
@with_sizes("medium")
def read_big_chunks(f):
- """ read 4096 bytes/chars at a time """
+ """ read 4096 units at a time """
f.seek(0)
while f.read(4096):
pass
@@ -108,28 +108,28 @@
@with_open_mode("w")
@with_sizes("small")
def write_bytewise(f, source):
- """ write one byte/char at a time """
+ """ write one unit at a time """
for i in xrange(0, len(source)):
f.write(source[i:i+1])
@with_open_mode("w")
@with_sizes("medium")
def write_small_chunks(f, source):
- """ write 20 bytes/chars at a time """
+ """ write 20 units at a time """
for i in xrange(0, len(source), 20):
f.write(source[i:i+20])
@with_open_mode("w")
@with_sizes("medium")
def write_medium_chunks(f, source):
- """ write 4096 bytes/chars at a time """
+ """ write 4096 units at a time """
for i in xrange(0, len(source), 4096):
f.write(source[i:i+4096])
@with_open_mode("w")
@with_sizes("large")
def write_large_chunks(f, source):
- """ write 1e6 bytes/chars at a time """
+ """ write 1e6 units at a time """
for i in xrange(0, len(source), 1000000):
f.write(source[i:i+1000000])
@@ -137,7 +137,7 @@
@with_open_mode("w+")
@with_sizes("small")
def modify_bytewise(f, source):
- """ modify one byte/char at a time """
+ """ modify one unit at a time """
f.seek(0)
for i in xrange(0, len(source)):
f.write(source[i:i+1])
@@ -145,7 +145,7 @@
@with_open_mode("w+")
@with_sizes("medium")
def modify_small_chunks(f, source):
- """ modify 20 bytes/chars at a time """
+ """ modify 20 units at a time """
f.seek(0)
for i in xrange(0, len(source), 20):
f.write(source[i:i+20])
@@ -153,29 +153,48 @@
@with_open_mode("w+")
@with_sizes("medium")
def modify_medium_chunks(f, source):
- """ modify 4096 bytes/chars at a time """
+ """ modify 4096 units at a time """
f.seek(0)
for i in xrange(0, len(source), 4096):
f.write(source[i:i+4096])
- at with_open_mode("w+")
+ at with_open_mode("wb+")
@with_sizes("medium")
def modify_seek_forward_bytewise(f, source):
- """ modify one byte/char every two """
+ """ alternate write & seek one unit """
f.seek(0)
for i in xrange(0, len(source), 2):
f.write(source[i:i+1])
f.seek(i+2)
- at with_open_mode("w+")
+ at with_open_mode("wb+")
@with_sizes("medium")
def modify_seek_forward_blockwise(f, source):
- """ modify 1000 bytes/chars every 2000 """
+ """ alternate write & seek 1000 units """
f.seek(0)
for i in xrange(0, len(source), 2000):
f.write(source[i:i+1000])
f.seek(i+2000)
+# XXX the 2 following tests don't work with py3k's text IO
+ at with_open_mode("wb+")
+ at with_sizes("medium")
+def read_modify_bytewise(f, source):
+ """ alternate read & write one unit """
+ f.seek(0)
+ for i in xrange(0, len(source), 2):
+ f.read(1)
+ f.write(source[i+1:i+2])
+
+ at with_open_mode("wb+")
+ at with_sizes("medium")
+def read_modify_blockwise(f, source):
+ """ alternate read & write 1000 units """
+ f.seek(0)
+ for i in xrange(0, len(source), 2000):
+ f.read(1000)
+ f.write(source[i+1000:i+2000])
+
read_tests = [
read_bytewise, read_small_chunks, read_lines, read_big_chunks,
@@ -189,7 +208,9 @@
modify_tests = [
modify_bytewise, modify_small_chunks, modify_medium_chunks,
+ None,
modify_seek_forward_bytewise, modify_seek_forward_blockwise,
+ read_modify_bytewise, read_modify_blockwise,
]
def run_during(duration, func):
@@ -260,6 +281,10 @@
options = options or "rwbt"
+ if "b" in options:
+ print("Binary unit = one byte")
+ if "t" in options:
+ print("Text unit = one character")
# Binary reads
if "b" in options and "r" in options:
print("\n** Binary input **\n")
@@ -272,7 +297,7 @@
# Binary writes
if "b" in options and "w" in options:
- print("\n** Streaming binary output **\n")
+ print("\n** Binary append **\n")
def make_test_source(name, size):
with open(name, "rb") as f:
return f.read()
@@ -281,7 +306,7 @@
# Text writes
if "t" in options and "w" in options:
- print("\n** Streaming text output **\n")
+ print("\n** Text append **\n")
def make_test_source(name, size):
with text_open(name, "r") as f:
return f.read()
More information about the Python-checkins
mailing list