MathGroup Archive 2010

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

Search the Archive

Re: Programing tips: What is faster?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113136] Re: [mg113040] Programing tips: What is faster?
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Fri, 15 Oct 2010 13:49:35 -0400 (EDT)
  • References: <201010120824.EAA19179@smc.vnet.net>

Hi Themis,

I have written a package called Cache, which takes a function and creates
its cached version, which can cache n most recent results, where <n> can be
specified. It is on my web site, along with a notebook with some examples of
use:

http://www.mathprogramming-intro.org/additional_resources.html

You may find it useful for your problem.

Regards,
Leonid


On Tue, Oct 12, 2010 at 1:24 AM, Themis Matsoukas <tmatsoukas at me.com> wrote:

> I recall reading that Mathematica saves its previous calculations so that
> it does not compute something unnecessarily if it has been computed already.
> Should I take this to mean that the following two examples would run equally
> fast?
>
> EXAMPLE 1
> =======
> f[MyList_] := Total[MyList]
> a = f[MyList]
> b = f[MyList]
>
> EXAMPLE 2
> =======
> f[MyList_] := Total[MyList]
> z = f[MyList]
> a = z
> b = z
>
> I have a lengthy simulation and I'm looking for ways to speed it up. The
> examples here are just a demonstration. In my actual calculation, f is a
> more complicated function, MyList changes during the course of the
> calculation,  and f is called several times, not necessarily in consecutive
> lines as shown here. Option #1 is preferable to me because it does not
> require me to check whether MyList has changed between calls, as I would
> have to do under #2. But if its slower because of the two calls to f, I'd
> invest the time to code my notebook according to #2.
>
> Thanks
>
> Themis
>
>



  • Prev by Date: Pi vs its decimal approximation
  • Next by Date: Re: Simplifying Logs
  • Previous by thread: Programing tips: What is faster?
  • Next by thread: Re: Programing tips: What is faster?