CompiledFunction in 3.0
Q: Version 3.0 sometimes takes considerably longer to generate plots than
Version 2.2. For example:
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr88.gif]](inoutgr88.gif)
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr89.gif]](inoutgr89.gif)
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr90.gif]](inoutgr90.gif)
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr91.gif]](inoutgr91.gif)
Evaluating the same expression in Version 2.2 is about eight times faster. Why is
version 3.0 so much slower?
David Withoff (withoff@wolfram.com) answers:
This difference is a result of a change in the way that handles overflow and underflow. In
Version 3.0, switches to uncompiled evaluation in cases of machine overflow or underflow.
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr94.gif]](inoutgr94.gif)
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr95.gif]](inoutgr95.gif)
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr96.gif]](inoutgr96.gif)
![[Graphics:inoutgr3.gif]](inoutgr3.gif) ![[Graphics:inoutgr97.gif]](inoutgr97.gif)
In Version 2.2, the same input would evaluate to zero.
The compiler is called automatically from . Compiled evaluation is faster for
this example than uncompiled evaluation. Many of the terms in generate machine underflow within
the range of the plot. Version 2.2 just replaces these terms with zero and continues with
compiled evaluation, which is often wrong, but which is probably fine in this example.
Version 3.0 is more careful; it switches to uncompiled evaluation when it detects
underflow, but that extra care has the unfortunate side effect of making this calculation
slower.
One workaround is to replace all of the expressions that might cause overflow or
underflow with conditional expressions. For example, one could replace with . |