Optimizing gcc compilation for mex files

(With many thanks to Alberto Martinez). There are a large number of different flags which can be used with gcc to optimize code for speed; these are described in the gcc documentation. The optimization options specified by default in the gnumex package are the following: -O3, which is relatively benign. However, you may well get considerably greater speed improvements by adding the following flags to your Mex options file manually: -ffast-math.  This option sacrifices some input checking for faster floating point maths. However, to quote from the gcc documenatation: "This option allows GCC to violate some ANSI or IEEE rules and/or specifications in the interest of optimizing code for speed. For example, it allows the compiler to assume arguments to the sqrt function are non-negative numbers and that no floating-point values are NaNs (Not-A-Number). This option should never be turned on by any `-O' option since it can result in incorrect output for programs which depend on an exact implementation of IEEE or ANSI rules/specifications for math functions."

Note also that you may get major gains in speed from optimizing for a particular processor.  See Intel 386 and AMD x86-64 Options.