Speed and Efficiency: When to Evaluate the Right-Hand-Side during a Function Definition
Let's set a baseline to check efficiency. Here we check timing to integrate something
We check the same thing again, because Mathematica may have spent some time loading algorithms to integrate
Here, we time how long it takes to create a function (with delayed assignment), but using Evaluate on the rhs.
The following is equivalent to the above (safer) definition---and will work so long as c is not assigned to an expression.
The following should take the *least* amount of time to perform, but as we shall see is not as efficient in the long run.
|
|
|
The following should give a rapid result
The following will not be rapid, because it has to do the symbolic integration before returning the result.
Created by Wolfram Mathematica 6.0 (23 October 2007) | ![]() |