Prev: preventing "out-of-memory" by codistributing arrays
Next: Global Variables Speed vs. Function Argument Variable Speed
From: Rune Allnor on 16 Feb 2010 07:36 On 16 Feb, 13:26, Uwe Brauer <o...(a)mat.ucm.es> wrote: > Ok if that is for say 3 dimensional partial diff eq matlab > is not for you, but frankly C and relatives I find sort of > ... Here you are at the core of your choise: Using matlab because you as user find it more convenient to interact with the available functionality than the casse is with some of the alternatives, is a perfectly valid argument in favour of matlab. You just have to be aware that the choise stands between one or the other: *Either* the convenient functionality, GUI, canned immediately useful routines etc, *or* run-time efficiency. Rune
From: Malcolm McLean on 16 Feb 2010 07:47
Uwe Brauer <oub(a)mat.ucm.es> wrote in message <87d405bfk7.fsf(a)mat.ucm.es>... > > I know about profile but is there any other tool available > to measure whether the code is efficient. Clock? Tic? > Write the code and make sure its correct. Then run it. If it completes within acceptable time, then its OK (unless ypu have to ship it out to thrid parties who might need bigger datasets). If it doesn't run in acceptable time, use profile to find out where it is spending its time. Then you've got to decide whether you can do algorithmic optimisation or not. Usually this involves replacing a simle algorithm with a more complex one that has lower order of runtime. For instance you can find a match in a list of strings by linear search, which is O(N), or you can make sure the list is sorted and do a binary search, which is O(log N). After you've got the order of ypur algorithm down as far as possible, try removing abstraction. Usually programs spend a not insignificant amunt of time reformatting data so that it is presented in a way that subroutines expect it. Eg one subroutine might want a cell array of strings, another an array of structs with a 'name' field, so you can rewrite the cell array of strings function to operate on the structure directly. This destroys its generality, but eliminates a reformat operation. If it is still too slow, try micro-optimisation. This involves things like removing unnecessary copies, or storing the strings as 8 bit integers rather than 16 bit characters. Also, in matlab, replacing for loops with implicit vector looping statements. This is the point at which clock timings are useful, because it is not always obvious whether micro-optimisation is in fact working. The most aggressive form of micro-optimsation is to rewrite the function as a C or Fortran Mex file. This can give 10x speed up. Micro-optimisation doesn't mean 'slight optimisation' but optimisation that doesn't change the operations. |