Accelerating Matlab

Matlab is a very useful programming environment, but it also has many
inefficiencies. You might think that these are unavoidable, but in fact it
is possible to fix most of them, without significantly changing your
programs. This page describes some easy ways to modify the Matlab
environment to make programs run faster.

Run mex -setup and select a good compiler.
The default compiler (lcc) does not produce very good code.

To use Microsoft Visual Studio .NET 2003 version 7.1,
you will first need to install a
patch.
Unfortunately, while Visual Studio 7.1 generally produces good code, it has a
performance bug in the intrinsic exp function. To get around
this, edit the mex options file
(C:\MATLAB6p5p1\bin\win32\mexopts\msvc71opts.bat) to read:

set OPTIMFLAGS=/MD -O2 -Oy- /Oi- -DNDEBUG

After changing the compiler, you should re-compile your mex files, and
re-install any packages including mex (such as lightspeed).

Install
lightspeed.
It provides optimized implementations of common operations, including a
C replacement for repmat.m.

Efficient ways to do common tasks

Manipulate sets of integers

The fastest way to do this is with sparse logical vectors. If you want to
use sorted arrays of integers instead, beware that the Matlab functions
setdiff, union, etc. are not optimized for this case
and will be a bottleneck.
Optimized functions for the sorted case are
included in lightspeed.

Represent a graph

Use a sparse logical adjacency matrix, and use matrix operations whenever
possible. For example, if G is symmetric (i.e. an undirected
graph) then G*G gives the number of neighbors in common to nodes
i and j, for all (i,j). See Kevin Murphy's graph toolbox.