I'd never really given speed a lot of thought when coding my Mathematica notebooks, but after recently attending a seminar I think it's something I need to spend some time thinking about. My sheets are normally fairly trivial in comparison to some of the large banking house notebooks that run, but what I was interested to hear was that some of the sheets being run take over 6 hours from the other delegates. That's a long time to wait to see if your numbers are rubbish.

Also what was interesting was that the presenter spends a lot of his time making other people's code work faster, essentially that's the core of his consultancy business. Some speed improvements were up to 912% faster.

So a 6 hour sheets would potentially run in less than 30 seconds. Which is a hell of a lot faster and lets you run various scenarios in a day rather than one a day.

One simple thing that I took away from all of this is if I'm only interested in numerical results rather than symbolic, then I need to think carefully about the level of precision I require.

For example using the /AbsoluteTiming flag you can do a simple test to see the difference that the level of precision makes. By simply adding a decimal point to the number 2 it will convert to machine level precision.

1 |
Nest[Sqrt[1 + #] &, 2, 1000]; // AbsoluteTiming |

Gives a timing of 0.283438 seconds on my machine. Simply adding a decimal place to the number 2 gives a significant speed jump.

1 |
Nest[Sqrt[1 + #] &, 2., 1000]; // AbsoluteTiming |

Gives a timing of 0.000293 seconds, which is a massive shift in computation time.

Something to consider.