interp1 vs interp1q R2015a
5 次查看(过去 30 天)
显示 更早的评论
Hi
First off I realise interp1q might be deprecated. They have stated that for several versions now.
I've been refactoring some code (on release 2015a) and being aware they improved interp1's performance considerably I thought I would test the speed between the two again.
Test Code:
x = [0;1];
y = [0;1];
xx = rand(1e7,1);
tic;interp1(x,y,xx);toc
tic;interp1q(x,y,xx);toc
The results:
Elapsed time is 0.051931 seconds.
Elapsed time is 1.866386 seconds.
Interp1 is now, well shall we say, massively quicker than interp1q. I haven't delved into the code but interp1q was always quicker because of less error checking etc. It seems clear that interp1q has not been touched while interp1 has moved along.
Any idea of how we can "rewrite" interp1q to make it faster than interp1 taking into account that error checking etc can be handled before entering the function?
PS: In some industries, interpolation is one of the most time consuming calculations, since it gets called millions of times. So even a small increase in speed makes a massive difference in overall run-time.
Regards,
Phil
2 个评论
John D'Errico
2015-4-1
1. Never use tic and toc to time code, unless you have no choice. (There are SOME circumstances where tic and toc are reasonable for use.) Use timeit instead. It will always give you better time predicitons.
2. A vector of only 2 points may be a poor test of these functions.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!