필터 지우기
필터 지우기

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 CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by