LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Code execution MathScript vs. MATLAB

Hi,

I'm working on a school project where I am supposed to compare MathScript and MATLAB functions, execution speeds and so on.

Here I give You a small example of code. The for loops are present because of time measurability.



function matice()
% Funkce ma za ukol cvicne operace s maticemi

clear all;
close all;
clc;


for j = 1:10

tic

for i = 1:5

A = randn(1000, 1000);
B = randn(1, 1000);

C = A * A;
D = B * A;
E = A + 2 * A + 3 * A;
F = B * B';

end

toc

end



The main problem is that in MATLAB it won't take more than 2.5s in MathScript more than 11s!(measured by tic-toc functions, working conditions were "exactly the same") Am I doing something wrong? How is it possible to speed it up?

I'm working in LabVIEW MathScript Window, NOT LabVIEW MathScript Node.

The Versions are LabVIEW 8.5(Professional Version), MATLAB 7.4.0.
And finally the computer which I am working on is Intel C2D E4500(2,20GHz), 2x1GB DDR2 RAM Dual-Channel, Windows XP x86 platform.

Thanks in advance.
0 Kudos
Message 1 of 10
(13,109 Views)

A difference of a factor of 4 or 5 is not that big and is probably caused by the fact that mathscript is implemented on top of LabVIEW. The two methods are well within an single order of magnitude. No big deal!

For additional information, read e.g. the following posts:

http://forums.ni.com/ni/board/message?board.id=MathScript&view=by_date_ascending&message.id=105#M105

Maybe you should also do your algorithm in pure LabVIEW to see how it compares. 😉 

0 Kudos
Message 2 of 10
(13,074 Views)
Hi altenbach,

thanks for Your reply. Maybe You're right about the cause of my problem.
Thanks also for the link. I've read it before. I wasn't interested as much in speed as in the difference between these two programs. If I have to compare something I must do it for the same conditions as much as it is possible. If You know what I mean. So I've did it in LabVIEW MathScript Window.
But such a coincidence! I planned to do it in pure LabVIEW and also through MathScript Nodes but first I checked my email and there was your reply.

So thanks for once more and sorry about the mistakes.

Bye.

Message Edited by Selatko on 01-25-2008 09:15 AM
0 Kudos
Message 3 of 10
(13,072 Views)
Hi all,

I've done my simple example in various ways. I'm posting it here in case someone would find it valuable(but I hardly doubt). If You will see any mistake or something You would do better way I would appreciate to let me know.

I've made four types of connections:
1) through MathScript Nodes, 1 iteration took time about t=2,1s
2) generation of matrix and vector is made in LabVIEW computations through Nodes, 1 iteration time t=1,8s
3) generation of matrix and vector is made through Nodes, computations in LabVIEW, 1 iteration time t=1,4s
4) and finaly completely in pure LabVIEW, 1 iteration time t=1,2s

Here are the attachements.

Bye.
Message 4 of 10
(13,061 Views)
Another attachements.
0 Kudos
Message 5 of 10
(13,060 Views)
And the last one.
Download All
0 Kudos
Message 6 of 10
(13,059 Views)
Selatko,
 
Here are some things that might help your LabVIEW code, allowing you to get a better comparison:
 
I noticed that you are using the "Get Date/Time in Seconds" primitive with a feedback node to time your loop.  The problem here is that this function can execute at any time with respect to the rest of the code in the loop, causing error.  A better way to time your code would be to use the "Tick Count (ms)" primitive before and after the entire loop, as shown in the attached image.  This will also be more equivalent to the Tic Toc function in MathScript.
 
In your m script you ran the loop 5 iterations, but in the LabVIEW code there is a constant of 6 wired to the loop terminal.  This means that the loop will execute 6 times.  Even though LabVIEW arrays are zero-based, the number wired to the Loop Count terminal determines the integer number of iterations, so you should use a value of 5 here.
 
You may want to consider using global variables (in MathScript) to pass values from one MathScript node to another, instead of passing the values by wire.  Here is a discussion on speeding up MathScript code:  http://forums.ni.com/ni/board/message?board.id=MathScript&message.id=105#M105
 
Chris M
0 Kudos
Message 7 of 10
(13,043 Views)
CMal,

Your Example looks pretty easy and functional. As You've noticed I'm no Pro in LabVIEW. I appreciate Your comment. I'll make some changes and will see how it change the results.

Thanks, Bye.
0 Kudos
Message 8 of 10
(13,032 Views)

Hi could we have your feedback regarding the improvement you did ?

Thanks, BR

ELP

0 Kudos
Message 9 of 10
(6,716 Views)

Hi ELP,

 

WOW! How could someone get to this 9 years old post? 🙂

 

Honestly, I don't already remember all the changes I did to my original concept. But hey, on the link below there is a thesis. It's in Czech but at the end of the document there are some attachments with the code. But one more note. Since I played with this MathScript baby 9 years ago a lot might have changed! Since then, I never had a chance to use MathScript again.

 

https://www.vutbr.cz/www_base/zav_prace_soubor_verejne.php?file_id=7236

 

0 Kudos
Message 10 of 10
(6,706 Views)