[Python-checkins] r45929 - sandbox/trunk/sio/bench_io.py sandbox/trunk/sio/io.py
guido.van.rossum
python-checkins at python.org
Sun May 7 05:45:28 CEST 2006
Author: guido.van.rossum
Date: Sun May 7 05:45:27 2006
New Revision: 45929
Modified:
sandbox/trunk/sio/bench_io.py
sandbox/trunk/sio/io.py
Log:
Add an essential optimization to buffered read() -- bypass the buffer
if there's no buffered data and the read size is >= bufsize.
Also tweak the I/O benchmark to show that this is now faster than
classic I/O.
Modified: sandbox/trunk/sio/bench_io.py
==============================================================================
--- sandbox/trunk/sio/bench_io.py (original)
+++ sandbox/trunk/sio/bench_io.py Sun May 7 05:45:27 2006
@@ -36,7 +36,7 @@
def reader():
buffer = bytes()
bufsize = 32*1024
- file = io.open(TFN, "rb", 32*1024)
+ file = io.open(TFN, "rb", 8*1024)
try:
while len(buffer) < N:
buffer += file.read(bufsize)
Modified: sandbox/trunk/sio/io.py
==============================================================================
--- sandbox/trunk/sio/io.py (original)
+++ sandbox/trunk/sio/io.py Sun May 7 05:45:27 2006
@@ -225,6 +225,13 @@
result = data
else:
result += data
+ elif n >= self._bufsize:
+ data = self._file.read(n)
+ n -= len(data)
+ if result is None:
+ result = data
+ else:
+ result += data
else:
self._buffer = self._file.read(max(n, self._bufsize))
self._bufptr = 0
More information about the Python-checkins
mailing list