Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove compatibilty for Python 2
  • Loading branch information
hugovk committed Dec 12, 2022
commit 25663f3dab7214cf8229b2d2957ee9a18e2661e6
31 changes: 13 additions & 18 deletions Tools/iobench/iobench.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
TEXT_ENCODING = 'utf8'
NEWLINES = 'lf'

# Compatibility
try:
xrange
except NameError:
xrange = range

def text_open(fn, mode, encoding=None):
try:
Expand Down Expand Up @@ -103,7 +98,7 @@ def seek_forward_bytewise(f):
f.seek(0, 2)
size = f.tell()
f.seek(0, 0)
for i in xrange(0, size - 1):
for i in range(0, size - 1):
f.seek(i, 0)

@with_open_mode("r")
Expand All @@ -113,7 +108,7 @@ def seek_forward_blockwise(f):
f.seek(0, 2)
size = f.tell()
f.seek(0, 0)
for i in xrange(0, size - 1, 1000):
for i in range(0, size - 1, 1000):
f.seek(i, 0)

@with_open_mode("rb")
Expand All @@ -137,28 +132,28 @@ def read_seek_blockwise(f):
@with_sizes("small")
def write_bytewise(f, source):
""" write one unit at a time """
for i in xrange(0, len(source)):
for i in range(0, len(source)):
f.write(source[i:i+1])

@with_open_mode("w")
@with_sizes("medium")
def write_small_chunks(f, source):
""" write 20 units at a time """
for i in xrange(0, len(source), 20):
for i in range(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 units at a time """
for i in xrange(0, len(source), 4096):
for i in range(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 units at a time """
for i in xrange(0, len(source), 1000000):
for i in range(0, len(source), 1000000):
f.write(source[i:i+1000000])


Expand All @@ -167,31 +162,31 @@ def write_large_chunks(f, source):
def modify_bytewise(f, source):
""" modify one unit at a time """
f.seek(0)
for i in xrange(0, len(source)):
for i in range(0, len(source)):
f.write(source[i:i+1])

@with_open_mode("w+")
@with_sizes("medium")
def modify_small_chunks(f, source):
""" modify 20 units at a time """
f.seek(0)
for i in xrange(0, len(source), 20):
for i in range(0, len(source), 20):
f.write(source[i:i+20])

@with_open_mode("w+")
@with_sizes("medium")
def modify_medium_chunks(f, source):
""" modify 4096 units at a time """
f.seek(0)
for i in xrange(0, len(source), 4096):
for i in range(0, len(source), 4096):
f.write(source[i:i+4096])

@with_open_mode("wb+")
@with_sizes("medium")
def modify_seek_forward_bytewise(f, source):
""" alternate write & seek one unit """
f.seek(0)
for i in xrange(0, len(source), 2):
for i in range(0, len(source), 2):
f.write(source[i:i+1])
f.seek(i+2)

Expand All @@ -200,7 +195,7 @@ def modify_seek_forward_bytewise(f, source):
def modify_seek_forward_blockwise(f, source):
""" alternate write & seek 1000 units """
f.seek(0)
for i in xrange(0, len(source), 2000):
for i in range(0, len(source), 2000):
f.write(source[i:i+1000])
f.seek(i+2000)

Expand All @@ -210,7 +205,7 @@ def modify_seek_forward_blockwise(f, source):
def read_modify_bytewise(f, source):
""" alternate read & write one unit """
f.seek(0)
for i in xrange(0, len(source), 2):
for i in range(0, len(source), 2):
f.read(1)
f.write(source[i+1:i+2])

Expand All @@ -219,7 +214,7 @@ def read_modify_bytewise(f, source):
def read_modify_blockwise(f, source):
""" alternate read & write 1000 units """
f.seek(0)
for i in xrange(0, len(source), 2000):
for i in range(0, len(source), 2000):
f.read(1000)
f.write(source[i+1000:i+2000])

Expand Down