summaryrefslogtreecommitdiff
path: root/benchmarks/casting.py
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2007-02-17 18:36:16 +0000
committerStefan van der Walt <stefan@sun.ac.za>2007-02-17 18:36:16 +0000
commit5cb3d759d601455e7e94b59d1baaf167782f3544 (patch)
treefe5b4e0e8939d69fd9fbed8e6c91fc003d94102e /benchmarks/casting.py
parent70c899f5940d2d2f99acbbc9906064e2028e25f9 (diff)
downloadnumpy-5cb3d759d601455e7e94b59d1baaf167782f3544.tar.gz
Refactor benchmarks.
Diffstat (limited to 'benchmarks/casting.py')
-rw-r--r--benchmarks/casting.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/benchmarks/casting.py b/benchmarks/casting.py
index cb498db10..5624fddfa 100644
--- a/benchmarks/casting.py
+++ b/benchmarks/casting.py
@@ -1,9 +1,17 @@
-import timeit
+from benchmark import Benchmark
+
+modules = ['numpy','Numeric','numarray']
+
+b = Benchmark(modules,
+ title='Casting a (10,10) integer array to float.',
+ runs=3,reps=10000)
+
N = [10,10]
-t1 = timeit.Timer('b = a.astype(int)','import numpy;a=numpy.zeros(shape=%s,dtype=float)'%N)
-t2 = timeit.Timer('b = a.astype("l")','import Numeric;a=Numeric.zeros(shape=%s,typecode="d")'%N)
-t3 = timeit.Timer("b = a.astype('l')","import numarray; a=numarray.zeros(shape=%s,typecode='d')"%N)
-print "1-D length = ", N
-print "NumPy: ", t1.repeat(3,1000)
-print "Numeric: ", t2.repeat(3,1000)
-print "Numarray: ", t3.repeat(3,1000)
+b['numpy'] = ('b = a.astype(int)',
+ 'a=numpy.zeros(shape=%s,dtype=float)' % N)
+b['Numeric'] = ('b = a.astype("l")',
+ 'a=Numeric.zeros(shape=%s,typecode="d")' % N)
+b['numarray'] = ("b = a.astype('l')",
+ "a=numarray.zeros(shape=%s,typecode='d')" % N)
+
+b.run()