LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript Nugget #4: Blazing Speed

The previous nuggets were tied together by one common thread: MathScript now knows the data type of every variable in your script. This is what allows you to see colors in data type highlighting, detailed information in the context help, and automatic selection of output data types. For a computer scientist like me, this is very cool in its own right: MathScript knows the type of every variable without you having to include any type declarations in your script. Compare this to LabVIEW’s formula node (and also the C programming language): in these languages, every variable must be preceded by a type declaration like “float” or “bool”. None of this is necessary in MathScript. In computer science terms, we’ve taken a loosely typed language and made it strictly typed.

But besides the usability features that this change enabled, there is one huge benefit of a strictly typed language: speed. In a loosely typed language, type checks and type resolution must happen at run-time. Are the inputs to my plus operator the same size? Are they compatible data types? What is the data type of the output? Questions like these are answered over and over, every time you run your script. These checks take time and end up slowing things down dramatically. MathScript pre-2009 was a victim of this: for many scripts, run-time performance was painfully slow.

But with strict types in 2009, MathScript hits a new stratosphere of performance. Gone are the days when MathScript was hundreds or thousands of times slower than pure LabVIEW code. MathScript still doesn’t quite match the blazing speed of G for every example you can imagine, but for many scripts it will be within 2x or even closer.

So if you gave up on MathScript in the past because it didn’t meet your performance needs, now is the time to give it a second look. We hope you’ll be pleasantly surprised!

 

jattas

LabVIEW MathScript R&D

 

ps Check out previous MathScript Nuggets here.

Message 1 of 13
(9,830 Views)

Hello,

 

Thanks a lot for the heads up jattas. I was worryibng about this, and creaed a small crude VI to test the performance of a Mathscript vs a Formula Node.

 

In my test, the Formula Node was approx 2.6 times faster. That is not critical in my app: What IS critical, is to be able to DEBUG (:-) ) the formulas which I have a LOT of in this application. I will present it at a later time.

 

 

 

Geir Ove
0 Kudos
Message 2 of 13
(9,488 Views)

Hi Geir,

 

I'm glad this nugget was helpful. I took a look at the code you attached and saw similar results on my machine. Also interesting to note: a "pure G" implementation that uses the Sine, Cosine, and Divide primitives performed about the same as the formula node. Hopefully MathScript can get to that level soon.

 

The MathScript Node has a huge advantage over the formula node for debugging. If you haven't already, be sure to check out the nuggets on probing and breakpoints.

 

Good luck!

 

jattas

LabVIEW MathScript R&D

0 Kudos
Message 3 of 13
(9,478 Views)

Hello Jattas,

 

 I do have a question that I cannot find the answer to, and I have searched for it many times:

 

Is it possible from a Mathscript to write to a Console Window that would pop up with the text written:

I want to write debug info and reminders in this window (console )  while testing.

 

If possible, please provide a short example !

 

 

Geir Ove
0 Kudos
Message 4 of 13
(9,436 Views)

Hi again,

 

In the MathScript Window, you can do this by typing a command without a semi-colon ( ; ) after it. This will print the result of the command in the output pane of the MathScript Window. So if you want a line of text, you could just type that string and MathScript will print it.

 

mswindow.png

 

You can do the same thing in your code in the MathScript Node. To see the output there, use the output tab of the MathScript Probe. You launch the probe by right-clicking on the MathScript Node and selecting "Probe" before it runs.

 

outputwindow.png

 

Is this the kind of thing you were looking for?

 

jattas

LabVIEW MathScript R&D

 

 

Message 5 of 13
(9,427 Views)

Hello Jattas,

 

Thanks a lot for your fast answer !

Your example showed me new ways to debug Mathscript, but unfortunately it was not what I was looking for:

 

The scenario is as follows: I have many (10 - 20) Mathscript nodes that does complex calculations that are under development: In some of them, there are issues that I need to remember to pay attentention to later:  In Java or C development environment, I would then write to the GLOBAL console e.g.: "In MyClass remember to check value of constant: tx" ... and so forth:

 

So, I need to write to a Global Console that draws my attention to things to be checked later.

 

Is there a way to do this?

 

With your example, I have to install Probes for all the 10 - 20 mathscript nodes each time I start LabView, and this is too cumbersome. 

Message Edited by geirove on 02-08-2010 04:24 PM
Geir Ove
0 Kudos
Message 6 of 13
(9,425 Views)

Hello again,

 

Update: The following Plot command does what I want, but is also cunbersome to use;

 

In two diferent Mathscript nodes I put the following:

 

 text(0,1, 'Test in k_V4') & in anotheri Put: text(0,2, 'Test in rb_V4')

 

This pops up a Global Plot window as shown in the attached picture.

 

However, its clumsy, since I have to remember the line numbers used... But, I recon it could be improved, but I do not have time to play with this right now...

 

Any better ideas or maybe you could come up with a customized Mathscript command that Uses the Plot Window as a Global Console?

 

 

 

 

 

 

 

 

Geir Ove
0 Kudos
Message 7 of 13
(9,422 Views)

Hi,

 

An alternative way is to write output to a file.

 

GlobalConsole.png

Message 8 of 13
(9,405 Views)

Hello,

 

Thanks.

 

File works, but does not give the "attention" I need. I want a Window to Popu Up (or a Console that is visible all the time) that show the important messages that should not be forgotten. It is easy to forget about the file messages, and you manually have to check them.

 

A console is available in all Text Based languages I know of, and  should be available for MathScript as well. NI will probably implement it some time, but until then I need a workaround.

 

Geir Ove
0 Kudos
Message 9 of 13
(9,403 Views)

Hi Geir,

 

I understand what you're looking for now. MathScript has a couple of functions that do similar things, but I can't think of a way to do exactly what you want. The dos and system functions can be used call any OS command. If you call them with an ampersand, they will even open a console window. For example, you could echo a message like this:

 

 

system('echo This is my message &')

 

 

Unfortunately, every time you call the command, it will open a new command window instead of re-using the one opened previously.

 

There may be a way to combine ttrr's suggestion with this approach. You could write your messages to a file and then use 'system' to show them all at the end of your program. I realize it's not ideal, but it's the best pure-MathScript solution I can come up with at the moment.

 

jattas

LabVIEW MathScript R&D

Message 10 of 13
(9,399 Views)