I think in general you can say: For < Table and in some cases For < Table < Map.Python version of matlab interp1 Interpolación de datos 1D (búsqueda en tabla) - MATLAB interp1. It just depends on the task which is faster, I often try both with varying result. But if you have a list of values, and you want to evaluate a function at those values, most often Map is the fastest. I often try to circumvent using table, but rather using Map Note that Table is not always slower, it is sometimes faster than Map. Mean and standard deviation of the results of the second run are: I repeated this a few time and see the same pattern every time.Įxecution two times of the loop. first call – functions are loaded into memoryĮlapsed time is 0.048815 seconds. (Assuming that not other processes are competing for the cpu-cycles.)Įlapsed time is 0.260425 seconds. I think that “… individual timings can vary wildy …” is not true regarding Matlab. I use R2008a on a 6+ years old Dell Precission 450 with Windows XP SP3. I assume you use the latest version of Matlab. Your timing of INTERP1 of Matlab surprises me. Maybe I need to do more sophicsticated timings than just tic and toc? I will invesitigate. NAG is still faster but not as much as I originally thought. What I don’t understand here is why my MATLAB score for this system is so much better than my other one since the hardware is almost identical. On the system where I currently sit (different from the one I used when I wrote the article) I get the following timings using the code in the article and the Mathematica code above. Evaluating them at 20001 different points (the length of the vector t in my example) is what takes the time and it was this time that we wanted to minimise. Finding the splines that fit the 7 datapoints is trivial no matter which package you use. I don’t think that you are comparing like for like. Thanks to the NAG technical support team for their assistance with this particular problem and to the postgraduate student who came up with the idea in the first place. Of course the real code contained a lot more than just a call to interp1 but using the above technique decreased the run time of the user’s application from 1 hour 10 minutes down to only 26 minutes. Of course y1 and y2 are identical as the following call to norm demonstrates norm(y1-y2) Which took 0.054958 seconds on my system making it around 9 times faster than the pure MATLAB solution – not bad at all for such a tiny amount of work. We can do exactly the same calculation using the NAG toolbox for MATLAB: tic The tic and toc statements are there simply to provide timing information and on my system the above code took 0.503 seconds. One way of doing this in MATLAB is to use the interp1 function as follows tic Y = Īnd you want to interpolate this data on a fine grid between x=0 and x=1 using piecewise cubic Hermite interpolation. Let’s say that you have the following data-set x = Rather than use her actual code, which is rather complicated and domain-specific, let’s take a look at a highly simplified version of her problem. Would it be possible to use the NAG toolbox for MATLAB (which hooks into NAG’s superfast Fortran library) to get her results faster she wondered? Between the two of us and the NAG technical support team we eventually discovered that the answer was a very definite yes. Recently I had an email from someone who had profiled her MATLAB code and had found that it was spending a lot of time in the interp1function. Often you can get very big speedups in return for only a modest amount of work and as a bonus you get to keep the use of both of your eyes. I have found that a MUCH better course of action is to profile the code, find out where the slow bit is and then do what you can with that. Telling such a person that they should throw their painstakingly put-together piece of code away and learn a considerably more difficult language in order to rewrite the whole thing is unhelpful at best and likely to result in the loss of an eye at worst. I have no doubt that some of you are thinking that the correct answer is something like ‘ completely rewrite it in Fortran or C‘ and if you are then I can only assume that you have never been face to face with a harassed, sleep-deprived researcher who has been sleeping in the lab for 7 days straight in order to get some results prepared for an upcoming conference. I often get sent a piece of code written in something like MATLAB or Mathematica and get asked ‘ how can I make this faster?‘.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |