Add --generator option to src/sorting/scaling.py.
authorW. Trevor King <wking@drexel.edu>
Mon, 25 Oct 2010 14:03:24 +0000 (10:03 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 25 Oct 2010 14:03:24 +0000 (10:03 -0400)
src/sorting/scaling.py

index c553ee4964111238084b678ad7d78ea39be7f8b5..712afbb7ff86ceceb7e39c2df7be2485f3b977f0 100755 (executable)
@@ -18,12 +18,12 @@ matplotlib.use('Agg')  # select backend that doesn't require X Windows
 import pylab
 
 
-def generate_data(stream, N, ordered=False):
+def generate_data(generator, stream, N, ordered=False):
     print >> sys.stderr, 'generate %d data points (ordered? %s)' % (
         N, ordered)
     stream.seek(0)
     stream.truncate()
-    args = ['./data.py', str(N)]
+    args = [generator, str(N)]
     if ordered:
         args.insert(1, '--ordered')
     q = subprocess.Popen(args, stdout=stream)
@@ -49,8 +49,8 @@ def run_test(executable, stdin=True, data_filename=None):
     assert status == 0, status
     return stop - start
     
-def run_tests(executable, stdin=True, data_file=None, ordered=False,
-              repeats=10, max_time=1e2):
+def run_tests(executable, stdin=True, generator='./data.py', data_file=None,
+              ordered=False, repeats=10, max_time=1e2):
     times = {}
     prev_time = 0
     N = 2
@@ -58,7 +58,7 @@ def run_tests(executable, stdin=True, data_file=None, ordered=False,
         print 
         ts = numpy.zeros((repeats,), dtype=numpy.double)
         for i in range(repeats):
-            generate_data(data_file, N, ordered=ordered)
+            generate_data(generator, data_file, N, ordered=ordered)
             ts[i] = run_test(executable, stdin, data_file.name)
         times[N] = ts
         prev_time = ts.mean()
@@ -76,6 +76,8 @@ def main(argv=None):
         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('-g', '--generator', dest='generator', default='./data.py',
+                 help='Executable generating the random source (%default).')
     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',
@@ -91,6 +93,7 @@ def main(argv=None):
     kwargs = {
         'executable': executable,
         'stdin': options.stdin,
+        'generator': options.generator,
         'data_file': data_file,
         'repeats': options.repeats,
         'max_time': options.max_time,