Optimize Code
Module creates unique variables each time it is executed. By writing a function using Block and globally unique variables, repeated execution is sped up because the variable-creation step is omitted.
Remove Module in favor of Block with globally unique variables.
Create an inactive function.
Out[2]= | |
Apply the transformation.
Out[3]= | |
Activate the code and the transformed code to make definitions for fModule and fBlock.
Compare values for random test values.
Out[5]= | |
Comparing timings for a large set of test values shows a factor of 2.5 speed improvement.
Out[6]= | |