フィルターのクリア

which has high speed performance MATLAB or C?

4 ビュー (過去 30 日間)
live to l e a r n  MATLAB
live to l e a r n MATLAB 2012 年 11 月 27 日
MATLAB or C?
  1 件のコメント
James Tursa
James Tursa 2012 年 11 月 27 日
Depends on what you are doing. Many of the built-in functions call optimized compiled C/C++ routines to do the actual work, so there would be no advantage to your writing such functions in C/C++ yourself.

サインインしてコメントする。

採用された回答

Jan
Jan 2012 年 11 月 27 日
編集済み: Jan 2012 年 11 月 27 日
C.
When you are talking about the run time. But, scientists have to solve problems and the time to solve a problem is:
Time to solve = design time + programming time + testing time + debugging time ...
+ run time + time for visualization of results
Obviously the run time is only a tiny piece of the work except for rare problems like solving gigantic linear algebra equations as in a benchmark. But especially for this problem Matlab and C should use exactly the same libraries: ATLAS, MKL, etc. Then Matlab and C have the same performance.
Look at this example:
figure('name', 'My cute test');
x = rand(1, 100) * 2 * pi;
t = sort(x);
y = sin(t);
plot(t, y, 'o');
title('I am the \bf{title}\rm')
Programming time: 40 seconds, test and debug time: 10 seconds (I wrote "sin(x)" at first), run time: negligible, visualization included in programming time already.
Now do this in C, and consider that I want to run this on Macs, Linux and Windows machines, and of course this means Window from NT to 8.
Another aspect: Matlab is designed to operate on matrices. This can be inefficient compared with an elementwise operation:
x = rand(1, 1e6);
T = any(abs(x) < 0.9) ...
Now Matlab creates t1=abs(x) at first, than t2=(t1 < 0.1) and the test by any() will trigger after the first few values already (Yes, I know the ABS() is silly here). Naturally an elementwise operation would be much cheaper here:
T = false;
for ii = 1:numel(x)
if abs(x(ii)) < 0.9
T = true;
break;
end
end
But unfortunately this loop is not really fast in Matlab, when the complete array must be checked, e.g. if the values are compared with 0.000001.
In Matlab, as in any other programming language, performance is not an inherent feature of the language, but the programmer has to exploit the inner structure of problem using a matching feature of the language.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by