diff options
author | Alan McIntyre <alan.mcintyre@local> | 2008-07-23 13:51:45 +0000 |
---|---|---|
committer | Alan McIntyre <alan.mcintyre@local> | 2008-07-23 13:51:45 +0000 |
commit | 252e1289d6fdb13ac02b88953881e694500e87ee (patch) | |
tree | d62687509056e5271c33518a417a57ef0121452c /numpy/lib/benchmarks/bench_arraysetops.py | |
parent | 1ab04d3ed8d4597922055396a9ba17f00bfc86ad (diff) | |
download | numpy-252e1289d6fdb13ac02b88953881e694500e87ee.tar.gz |
Standardized NumPy import as "import numpy as np".
Moved unique1d benchmarking code to new benchmarks directory.
Diffstat (limited to 'numpy/lib/benchmarks/bench_arraysetops.py')
-rw-r--r-- | numpy/lib/benchmarks/bench_arraysetops.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/numpy/lib/benchmarks/bench_arraysetops.py b/numpy/lib/benchmarks/bench_arraysetops.py new file mode 100644 index 000000000..2c77fb758 --- /dev/null +++ b/numpy/lib/benchmarks/bench_arraysetops.py @@ -0,0 +1,65 @@ +import numpy as np +import time +from numpy.lib.arraysetops import * + +def bench_unique1d( plot_results = False ): + exponents = np.linspace( 2, 7, 9 ) + ratios = [] + nItems = [] + dt1s = [] + dt2s = [] + for ii in exponents: + + nItem = 10 ** ii + print 'using %d items:' % nItem + a = np.fix( nItem / 10 * np.random.random( nItem ) ) + + print 'unique:' + tt = time.clock() + b = np.unique( a ) + dt1 = time.clock() - tt + print dt1 + + print 'unique1d:' + tt = time.clock() + c = unique1d( a ) + dt2 = time.clock() - tt + print dt2 + + + if dt1 < 1e-8: + ratio = 'ND' + else: + ratio = dt2 / dt1 + print 'ratio:', ratio + print 'nUnique: %d == %d\n' % (len( b ), len( c )) + + nItems.append( nItem ) + ratios.append( ratio ) + dt1s.append( dt1 ) + dt2s.append( dt2 ) + + assert np.alltrue( b == c ) + + print nItems + print dt1s + print dt2s + print ratios + + if plot_results: + import pylab + + def plotMe( fig, fun, nItems, dt1s, dt2s ): + pylab.figure( fig ) + fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 ) + fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 ) + pylab.legend( ('unique', 'unique1d' ) ) + pylab.xlabel( 'nItem' ) + pylab.ylabel( 'time [s]' ) + + plotMe( 1, pylab.loglog, nItems, dt1s, dt2s ) + plotMe( 2, pylab.plot, nItems, dt1s, dt2s ) + pylab.show() + +if __name__ == '__main__': + bench_unique1d( plot_results = True ) |