"""Measure how a sorting executable scales with N.
-The executable should support the following usage:
+The executable should support one of the following:
executable path/to/data/file
+ cat path/to/data/file | executable
Where the data file is of the format output by data.py.
"""
assert status == 0, status
stream.flush()
-def run_test(executable, data_filename):
+def run_test(executable, stdin=True, data_filename=None):
print >> sys.stderr, 'run %s' % executable
+ if stdin:
+ with open(data_filename, 'r') as f:
+ contents = f.read()
start = time.time()
- q = subprocess.Popen([executable, data_filename],
- stdout=open('/dev/null', 'w'))
- status = q.wait()
+ if stdin:
+ p = subprocess.Popen([executable],
+ stdout=open('/dev/null', 'w'))
+ p.communicate(contents)
+ else:
+ p = subprocess.Popen([executable, data_filename],
+ stdout=open('/dev/null', 'w'))
+ status = p.wait()
stop = time.time()
assert status == 0, status
return stop - start
-def run_tests(executable, data_file, ordered=False, repeats=10, max_time=1e2):
+def run_tests(executable, stdin=True, data_file=None, ordered=False,
+ repeats=10, max_time=1e2):
times = {}
prev_time = 0
N = 2
ts = numpy.zeros((repeats,), dtype=numpy.double)
for i in range(repeats):
generate_data(data_file, N, ordered=ordered)
- ts[i] = run_test(executable, data_file.name)
+ ts[i] = run_test(executable, stdin, data_file.name)
times[N] = ts
prev_time = ts.mean()
N *= 2
p = optparse.OptionParser(
usage='%prog [options] executable', epilog=__doc__)
+ p.add_option('-s', '--stdin', dest='stdin', default=False,
+ action='store_true', help='Use the stdin executable syntax.')
p.add_option('-r', '--repeats', dest='repeats', default=10, type='int',
help='Number of repeats to run at each N (%default).')
p.add_option('-m', '--max-time', dest='max_time', default=1e2,type='float',
data_file = tempfile.NamedTemporaryFile()
kwargs = {
'executable': executable,
+ 'stdin': options.stdin,
'data_file': data_file,
'repeats': options.repeats,
'max_time': options.max_time,