Skip Montanaro skip at pobox.com
Wed Mar 17 02:48:06 CET 2004

```    Dave> Interesting.  I just ran a test comparing 10,000 calls to the
Dave> original h23 above with 10,000 calls to h23a below.

...

Dave> The results are very close:

Dave>    time/loop (sec)    %
Dave> Test 1: 6.48E-006   119.1 (class PZfuncs)
Dave> Test 2: 6.88E-006   126.4 (module PZfuncs)
Dave> Test 3: 5.44E-006   100.0 (z1, p1, etc  outside loop)

I'm not sure what these particular tests are measuring.  I can't tell which
are h23() calls and which are h23a() calls, but note that because h23() and
h23a() are actually quite simple, the time it takes to call them is going to
be a fair fraction of all calls.

For timing stuff like this I recommend you use timeit.py.  Most people here
are getting used to looking at its output.  Put something like:

import PZfuncs
h0 = PZfuncs.h0
z1 = PZfuncs.z1; z2 = PZfuncs.z2
p1 = PZfuncs.p1; p2 = PZfuncs.p2; p3 = PZfuncs.p3

def h23null(freq):
pass

def h23a(freq):
s = complex(2*pi*freq)
return h0*(s-z1)*(s-z2)/((s-p1)*(s-p2)*(s-p3))

def h23b(freq):
z = PZfuncs
s = complex(2*pi*freq)
return z.h0*(s-z.z1)*(s-z.z2)/((s-z.p1)*(s-z.p2)*(s-z.p3))

into h23.py then run timeit.py like:

timeit.py -s "import h23 ; freq = NNN" "h23null(freq)"
timeit.py -s "import h23 ; freq = NNN" "h23a(freq)"
timeit.py -s "import h23 ; freq = NNN" "h23b(freq)"

Its output is straightforward and pretty immediately comparable across the
runs.  The h23null() run will give you some idea of the call overhead.  You
can, of course, dream up h23[cdefg]() variants as well.

Post code and results and we'll be happy to throw darts... :-)

Skip

```