LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build Array function is the worst?

Hi,
I have a subVI that parses a message string to take out several values and then converts each value to a double. Then I proceed to build an array out of those doubles using the build array funtion. (the size is about 30 elements) Now would it really improve my performance if instead I initialize an array of 30 0's and then just replace each element one by one in the VI or should I just leave the build array function in there?
0 Kudos
Message 1 of 13
(4,202 Views)
Helper;

I created the following vi in a hurry. At least it does not initialize an array first. Maybe it can give you ideas.

Regards;
Enrique
www.vartortech.com
0 Kudos
Message 2 of 13
(4,202 Views)
Helper wrote:
>
> Hi,
> I have a subVI that parses a message string to take out several
> values and then converts each value to a double. Then I proceed to
> build an array out of those doubles using the build array funtion.
> (the size is about 30 elements) Now would it really improve my
> performance if instead I initialize an array of 30 0's and then just
> replace each element one by one in the VI or should I just leave the
> build array function in there?

Build Array is probably fine for about 30 elements. For thousands, you
might do better with Initialize Array and Replace Array Element.

You'll probably find that the string parse takes most of the time.

Mark
0 Kudos
Message 3 of 13
(4,202 Views)
Hi,
Thanks, but lets say I know for a fact that my array will always be 30 elements, wouldn't it be better to just initialize it at that and then just use 30 replace element functions every time as opposed to rebuilding the array?
0 Kudos
Message 4 of 13
(4,202 Views)
It might be marginally more efficient in terms of execution speed, yes.
However it makes the code slightly harder to write and read. There's little
in it either way.

Note the attachment that Enrique supplied isn't much better since the array
still has to grow dynamically. It could be adapted if your array will aways
be 30 elements; replace it with a FOR loop and the 30 element array will
transparently be pre-created and filled as the loop runs. Can't with the
while loop because Labview doesn't know how many times the loop will
iterate.

Alternatively, why bother with this arsing about? Just use "Spreadsheet
String to Array" and wire the correct datatype to the "type" input. You'll
then get probably the most efficient conversion you can get.

H
elper wrote in message
news:50650000000500000092530000-1007855737000@exchange.ni.com...
> Hi,
> Thanks, but lets say I know for a fact that my array will always be 30
> elements, wouldn't it be better to just initialize it at that and then
> just use 30 replace element functions every time as opposed to
> rebuilding the array?
0 Kudos
Message 5 of 13
(4,202 Views)
Thanks, but in my case I'm not sure that I could use the Spreadsheet String to Array because I have to take a lot more values out of the message string (approx. 45, not to mention that most of them are not doubles) then do some conversions and then come up with my 30 element array of doubles. With that being the case and me caring about efficiency ONLY (and not the complexity of writing the code) then I should use the Replace Array elements OR is there still some way of using the Spreadsheet String to Array to improve execution?
0 Kudos
Message 7 of 13
(4,202 Views)
Hi Helper,

The answer to question depends on which version of LV you are running. In pre-LV 6 I would religiously use the replace array element technique anytime I had large buffers or was performing an operation repeatedly.

When LV 6i came out, NI was pushing that the array operations where now optimized. So, I pulled my bench-marking VI's and found out the the build array inside a FOR loop performed almost identicly to the replace method!

So, if (version < 6.0) and (large_buffer = true OR repeated_operation) then use replace.
Else,
use build array.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 13
(4,202 Views)
I think you are the only person that has actually said that using build array is about the same as Replace Array. I am using version 6.0.2, but I must disagree that it is identical. I had a VI that used the build array function in a loop and it killed my execution speed I then went ahead and replaced the scheme with a Replace Array one and it was considerably faster. I'm not saying that you are wrong, because I'm sure you know more about this than I do, but from my personal experience this si what I found.
0 Kudos
Message 8 of 13
(4,202 Views)
Hi Helper,

Your reply has got me thinking.
Was it a FOR loop? If I remember correctly, it was the FOR loop that could figure out a head of time how big a buffer to allocate.

As indicated by someone else, the while loop can not tell how big a buffer to allocate.

Just trying to help,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 13
(4,202 Views)
Now it makes sense! But I have a for loop inside a while loop, is that a problem or that should not make a difference?
Alex
0 Kudos
Message 10 of 13
(4,202 Views)