Skip to content
Browse files

RAID tests

  • Loading branch information...
1 parent 213fcec commit 3710a9fb44495ccd0124f553b4ff1e57105b4d86 @lbolla committed May 8, 2012
Showing with 116 additions and 0 deletions.
  1. +82 −0 RAID/benchmarks/bench.py
  2. +3 −0 RAID/benchmarks/read
  3. +22 −0 RAID/benchmarks/tutorial.py
  4. +9 −0 RAID/setup.sh
View
82 RAID/benchmarks/bench.py
@@ -0,0 +1,82 @@
+# TODO
+# creation
+# slicing
+# modifying
+
+import numpy
+
+
+def numpy_create(nrows, ncols):
+ data = numpy.zeros((nrows, ncols))
+
+
+def numpy_create_record(nrows, dtype):
+ data = numpy.zeros((nrows,), dtype=dtype)
+
+
+def numpy_slice(data):
+ s = data[3, :].sum()
+ s = data[:, 3].sum()
+
+
+def numpy_slice_record(data):
+ s = data['f0'].sum()
+ # Note: cannot sum fields of a record
+ s = data['f3'].sum()
+
+
+def numpy_modify(data):
+ data[3, :].fill(666)
+ data[:, 3].fill(999)
+ data[0, :] = data[1, :]
+ data[10, :] = numpy.sin(data[11, :]) + numpy.cos(data[12, :])
+
+
+def numpy_modify_record(data):
+ data['f0'].fill(666)
+ data['f3'].fill(999)
+ data['f0'] = data['f3']
+ data['f10'] = numpy.sin(data['f11']) + numpy.cos(data['f12'])
+
+
+def make_random_array(nrows, ncols):
+ return numpy.random.random_sample((nrows, ncols))
+
+
+def make_random_recarray(nrows, ncols):
+ dtype = ','.join(['f4'] * ncols)
+ data = numpy.zeros((nrows, ), dtype=dtype)
+ for i in xrange(nrows):
+ data[i] = tuple(numpy.random.random_sample(ncols))
+ return data
+
+
+def bench(stmt, setup):
+ number_of_times, repetitions = 100, 3
+ t = Timer(stmt, setup)
+ elapsed_time = sum(t.repeat(number=number_of_times, repeat=repetitions)) / \
+ (repetitions * number_of_times)
+ print '%-50s: %.3f ms' % (stmt[:50], elapsed_time * 1000)
+
+
+if __name__ == '__main__':
+ from timeit import Timer
+ import inspect
+
+ ls = locals().copy()
+ functions = [k for k, v in ls.iteritems() if inspect.isfunction(v)]
+ stmts = ['from __main__ import %s' % ','.join(functions),
+ 'data = make_random_array(1000, 1000)',
+ 'recdata = make_random_recarray(1000, 1000)',
+ ]
+ setup_stmt = ';'.join(stmts)
+
+ for stmt in [
+ 'numpy_create(1000, 1000)',
+ 'numpy_create_record(1000, "%s")' % ','.join(['f4'] * 1000),
+ 'numpy_slice(data)',
+ 'numpy_slice_record(recdata)',
+ 'numpy_modify(data)',
+ 'numpy_modify_record(recdata)',
+ ]:
+ bench(stmt, setup_stmt)
View
3 RAID/benchmarks/read
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+w3m http://pytables.github.com/usersguide/libref.html#library-reference
View
22 RAID/benchmarks/tutorial.py
@@ -0,0 +1,22 @@
+from tables import *
+
+class Particle(IsDescription):
+ name = StringCol(16)
+ idnumber = Int64Col()
+
+h5file = openFile('tutorial1.h5', mode='w', title='test file')
+group = h5file.createGroup('/', 'detector', 'Detector Information')
+table = h5file.createTable(group, 'readout', Particle, 'Readout example')
+
+print h5file
+
+particle = table.row
+
+for i in xrange(10):
+ particle['name'] = 'particle %d' % i
+ particle['idnumber'] = i
+ particle.append()
+
+table.flush()
+
+print h5file
View
9 RAID/setup.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+sudo pacman -S hdf5
+
+pip install numpy
+pip install numexpr
+pip install Cython
+pip install tables
+pip install ipython

0 comments on commit 3710a9f

Please sign in to comment.
Something went wrong with that request. Please try again.