mailSome more speed up tips for the 'B14' dispersion models.


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on May 07, 2014 - 15:13:
Hi Troels,

As a useful learning exercise for your interest in speeding other
dispersion analyses, I have a few more small tips for squeezing a
little more speed out of the lib.dispersion.b14 code:

1)  Firstly

(x + y) * z,

is faster than

x*z + y*z.

The first has one sum and one multiplication.  The second has one
additional multiplication.  Now look at line 230 of the
lib.dispersion.b14 module.  You will see that inv_tcpmg would fit into
this exact pattern - it currently has the second form ;)


2)  On line 159 there is the code "4 * k_BA * k_AB".  Python type
conversions can be avoided by using "4.0 * k_BA * k_AB".  The zeta
equation on the previous line has a '2' which could be '2.0'.


That's pretty much all I can find.  There are other optimisations
possible, for example doing cleaver things with numpy objects higher
up in the looping, though these would require a lot of planning and
testing.  Another trick is actually to reformulate the original
equations in a way that would be faster in code.  I have used this for
the model-free analysis in relax to simplify the model-free spectral
density function equations.  These additional tricks would require too
much time - I wouldn't recommend it.  But it's good to keep in mind
that this could be made faster, if someone was determined enough.

Anyway, with the above and all your other optimisations, the code
should now be significantly faster.  And you should now know quite a
few tricks for writing faster code :)

Regards,

Edward



Related Messages


Powered by MHonArc, Updated Wed May 07 16:20:11 2014