Information Technology Reference
In-Depth Information
times as iterated in the loop. This causes the program to run much more slowly than
in the case where we could just execute pre-made machine instructions. The benefit
is that we get a high degree of flexibility; statements and data structures can change
dynamically at run time in a safe and convenient way from a user's point of view.
Interactive computing is one application of this flexibility.
Comparing implementations of Algorithm 6.4 in different languages shows that
the speed of the various programs varies greatly. Using compiled languages results
in significantly faster programs than interpreted languages. Some numerical appli-
cations require so much computing power that one is forced to use the fastest
algorithms and languages in order to solve the problem at hand. Other applications
demand only minutes or hours of execution time on a desktop computer, and in
these cases one can often trade computational efficiency in favor of increased human
efficiency, i.e., quicker, safer and more convenient programming.
6.2.3
Built-in High-Performance Utilities
Programming in Fortran, C, C CC , and Java can be very different from program-
ming in Maple, Matlab, and Python, especially when it comes to algorithms with
loops. In the former four languages you can implement a loop as in Algorithm 6.4
using basic loop constructions in those languages, and the performance will be very
good. This means that there will often be small differences between your implemen-
tation and a professional implementation of the algorithm made available through
a numerical library. Many researchers and engineers like to create their own imple-
mentation of algorithms to have full control of what is going on. This strategy often
leads to only a minor loss of performance.
The situation is different in Maple and Python, and also to some extent in Matlab.
Plain loops in these languages normally lead to slow code. A Maple implementation
of Algorithm 6.4 can easily be more than 150 times slower than a similar imple-
mentation in Fortran 77. However, this comparison is not fair. Plain, long loops in
Maple are to some extent a misuse of the language, especially if we try to imple-
ment algorithms that are available in libraries or as a part of the language. Numerical
integration is an example; Maple has a rich functionality for numerical integration,
where accuracy and performance can be controlled. Calling up a built-in numerical
integration rule in Maple (which means an algorithm of much higher sophistica-
tion than the trapezoidal rule) produces a result in about the same time as required
by our hand-made Fortran 77 function. In other words, you should not consider
implementation of basic numerical algorithms in Maple, because this will give low
performance; you should utilize built-in functionality. Clearly, not all algorithms are
available in Maple, and sometimes you have to make your own implementations. It
is then important to try to break up the steps in an algorithm into smaller steps,
which may be supported by built-in functionality.
The comments about Maple are also relevant for Matlab and Python. All these
three programming platforms have a large collection of highly optimized functions
Search WWH ::




Custom Search