From 15c3e37240f79987a308fb38d680944ede5ea739 Mon Sep 17 00:00:00 2001 From: Victor Leikehman Date: Thu, 2 Oct 2014 02:29:36 +0300 Subject: [PATCH] timing --- smop/Makefile | 18 ++++++++++++++++++ smop/go.m | 2 +- smop/go.py | 35 ++++++++++++++++++++--------------- smop/runtime.py | 4 ++-- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/smop/Makefile b/smop/Makefile index 7a10a1e6..e1c02161 100644 --- a/smop/Makefile +++ b/smop/Makefile @@ -1,5 +1,23 @@ FLAGS= +timer_so: a.so + rm -f a.py a.pyc + python go.py + +timer_py: a.py + python go.py + +clean: + rm -f a.* *.pyc + +a.so: a.c + gcc -I /usr/include/python2.7 -L /usr/lib/python2.7 -O2 -shared -o a.so a.c + +a.py: solver.m r8_random.m + python main.py $^ + +a.c: a.py runtime.py + cython a.py check: python runtime.py $(FLAGS) python test_runtime.py $(FLAGS) diff --git a/smop/go.m b/smop/go.m index 3602a82d..d005591c 100644 --- a/smop/go.m +++ b/smop/go.m @@ -17,4 +17,4 @@ mv = solver(ai,af,0); toc -disp(mv); +%disp(mv); diff --git a/smop/go.py b/smop/go.py index 586931fe..3e45d12b 100644 --- a/smop/go.py +++ b/smop/go.py @@ -1,21 +1,26 @@ -import numpy +import numpy,time import a from runtime import * -ai = matlabarray(zeros_(10,10,dtype=int)) -af = copy_(ai) +def main(): + ai = matlabarray(zeros_(10,10,dtype=int)) + af = copy_(ai) -ai[1,1]=2 -ai[2,2]=3 -ai[3,3]=4 -ai[4,4]=5 -ai[5,5]=1 + ai[1,1]=2 + ai[2,2]=3 + ai[3,3]=4 + ai[4,4]=5 + ai[5,5]=1 -af[9,9]=1 -af[8,8]=2 -af[7,7]=3 -af[6,6]=4 -af[10,10]=5 + af[9,9]=1 + af[8,8]=2 + af[7,7]=3 + af[6,6]=4 + af[10,10]=5 -mv = a.solver_(ai,af,0) -print mv + t0 = time.clock() + mv = a.solver_(ai,af,0) + t1 = time.clock() + print t1-t0 +if __name__ == '__main__': + main() diff --git a/smop/runtime.py b/smop/runtime.py index cd11fa26..cd2196b6 100644 --- a/smop/runtime.py +++ b/smop/runtime.py @@ -569,12 +569,12 @@ def strread_(s, format="", nargout=1): if format == "": a = [float(x) for x in s.split()] return tuple(a) if nargout > 1 else np.asanyarray([a]) - raise ErrorNotImplemented + raise NotImplementedError def strrep_(a,b,c): if isinstance(a,str): return a.replace(b,c) - raise ErrorNotImplemented # cell arrays + raise NotImplementedError # cell arrays def sum_(a, dim=None): if dim is None: