Skip to content

Commit

Permalink
add buffer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegt committed Sep 7, 2016
1 parent 9773f48 commit 940d6a7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lab/file_buffer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python

'''
file buffering performance test
'''

import sys
import timeit

fn = sys.argv[1]

print "prime fs page cache...",
open(fn,'r').read()
print "done"

def readall(fn, size):
fh = open(fn, 'r')
while True:
x = fh.read(size)
if len(x) == 0:
break
fh.close()

for size in (1,4096,65536):
print "read %d bytes at a time..." % size
t = timeit.Timer('readall("%s", %d)' % (fn, size),
setup="from __main__ import readall")
s = t.timeit(10)
print "%9.5f seconds" % s

28 changes: 28 additions & 0 deletions lab/stdin_buffer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python

'''
stdin buffering performance test
./stdin_buffer_test.py 1 < /tmp/random.data
./stdin_buffer_test.py 4096 < /tmp/random.data
./stdin_buffer_test.py 65536 < /tmp/random.data
'''

import sys
import timeit

size = int(sys.argv[1])

def readall(size):
while True:
x = sys.stdin.read(size)
if len(x) == 0:
break

print "read %d bytes at a time..." % size
t = timeit.Timer('readall(%d)' % (size),
setup="from __main__ import readall")
s = t.timeit(1)
print "%9.5f seconds" % s

0 comments on commit 940d6a7

Please sign in to comment.