标签:
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.
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).
profile on myfun; profile report
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.
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.
Use the functions provided in lightspeed.
Peter Rysadter‘s XML parser was the fastest, but is no longer available. Check out the links at Undocumented XML functionality.
文章转载自 Tom Minka 的 Accelerating Matlab。
标签:
原文地址:http://www.cnblogs.com/VVingerfly/p/4722449.html