MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Block vs. Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15590] Block vs. Module
  • From: Eckhard Hennig <hennig at itwm.uni-kl.de>
  • Date: Thu, 28 Jan 1999 04:23:22 -0500 (EST)
  • Organization: ITWM
  • Sender: owner-wri-mathgroup at wolfram.com

Recently, while profiling some rather large Mathematica 3.0 programs, my
colleagues and I discovered that simply exchanging all Module
statements in a package against Block statements reduced the total
computation time considerably. In one particular case with a large
number of function calls and local variables the execution time was
reduced by almost 50%.

The Mathematica documentation describes Block as a structure that allows
for temporarily assigning local values to global names, as opposed to
Module which defines new local symbols (which obviously takes a lot
more time). Thus, rather than Module, Block allows to make use of some
side effects on global symbols, but this should not happen in
well-structured programs. Due to the extreme speed differences we
encountered we are now asking ourselves if there is actually any good
reason against generally using Block instead of Module in Mathematica
packages. Are there any internal implementation issues that need to be
taken in account (such as heap management or stack size limitations)?

Best regards,

  Eckhard Hennig

----------------------------------------------------------- Dipl.-Ing.
Eckhard Hennig      mailto:hennig at itwm.uni-kl.de Institut fuer Techno-
und Wirtschaftsmathematik e.V. (ITWM) Erwin-Schroedinger-Strasse, 
67663 Kaiserslautern,  Germany
  Voice: +49-(0)631-205-3126    Fax: +49-(0)631-205-4139
    http://www.itwm.uni-kl.de/as/employees/hennig.html

     ITWM - Makers of Analog Insydes for Mathematica
        http://www.itwm.uni-kl.de/as/products/ai
-----------------------------------------------------------





  • Prev by Date: RE: Color problem with listdensityplot. Please HELP
  • Next by Date: Re: nb file from mac to windows
  • Previous by thread: Re: D vs. Derivative
  • Next by thread: Re: Block vs. Module