Borrar filtros
Borrar filtros

which has high speed performance MATLAB or C?

4 visualizaciones (últimos 30 días)
live to l e a r n  MATLAB
live to l e a r n MATLAB el 27 de Nov. de 2012
MATLAB or C?
  1 comentario
James Tursa
James Tursa el 27 de Nov. de 2012
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.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 27 de Nov. de 2012
Editada: Jan el 27 de Nov. de 2012
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.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by