import compiler import Numeric import numarray import numarray._numarray as _numarray import numarray.memory as memory import numarray._ufunc as _ufunc import sys import string import re import profile import hotshot import hotshot.stats import timeit from optparse import OptionParser parameters = """ p=int(10.0**i); a=arange(p); j=int(10.0**(i/4.0)); b=reshape(arange(j*j),(j,j)); c=a.copy(); d=a.copy(); e=transpose(b); f=transpose(b); af=a.astype('d'); cf=a.astype('d'); z=array(0); w=array(p); t=[1]*p; """ param_funcs = ["arange", "array", "reshape", "transpose"] benchmarks = """ take(a,c) put(a,c,d) transpose(b) putmask(a,c%2,d) repeat(a,2) choose(a%2,(a,c)) ravel(b) nonzero(a) where(a%2,a,c) compress(a%2,a) diagonal(b) trace(b) searchsorted(a,a) searchsorted(a,w/5) searchsorted(a,w/2) sort(a) sort(a,kind='quicksort') sort(a,kind='mergesort') sort(a,kind='heapsort') argsort(a) argsort(a,kind='quicksort') argsort(a,kind='mergesort') argsort(a,kind='heapsort') argmax(b) array(t) array(t,typecode='i') dot(b,b) innerproduct(b,b) clip(a,50,100) indices((100,100)) swapaxes(b,0,-1) concatenate((a,a,a)) innerproduct(b,b) outerproduct(b[0],b[0]) resize(a,(int(2*10**i),)) a[0] # single element b[0] # single row b[0,0] # multi-index single element b[0][0] # multi-index by view a[1000:2000] # 1D slice b[400:600,400:600] # 2D slice arange(int(10.**i)) identity(int(i+2)) a+c a+1 a+=c a+=1 a 1.0: alert = "-" elif change < 1.0: alert = "+" else: alert = "." if not re.match("\d+", words1[0]): print l1.strip() print l2.strip(), "\t", alert, change else: print " "*29, l1.strip() print " "*29, l2.strip(), "\t", alert, change def main(): parser = OptionParser() parser.add_option("-p", "--powers", dest="powers", help="powers of 10 to bencmark", metavar="POWERS", default="[0,5.0]") (options, args) = parser.parse_args() POWERS = eval(options.powers) if len(args) == 0: benchmark(powers=POWERS) else: if sys.argv[1] == "prof": for b in sys.argv[1:]: profall(b, powers=POWERS) elif sys.argv[1] == "ratio": ratio(sys.argv[2], sys.argv[3]) else: for b in args: benchmark(b, powers=POWERS) if __name__ == "__main__": main()