From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

variant set attribute- how fast it is?

Solved!
Go to solution

Hello

 

On NI days there was presentation about variant atributes. There was example saying that variant can be used to remove duplicates from 1D array and this supposed to be very fast solution. I did some test and it seems that it isn't :

 

 

On the other hand variant is very fast at searching once all atrubutes are set up.

 

 

Som my question is how fast is process of setting variant atributes and how this variant structure is allocated and stored in memory.

 

VI snippets attached.

 

Download All
0 Kudos
Message 1 of 11
(3,352 Views)

You should attach the actual VIs. Snippets do not reproduce  all VI settings.

You should use "high resolution relative seconds" for the timing.

Make sure your code does not get deadstripped, because there is no output used

0 Kudos
Message 2 of 11
(3,330 Views)

Here it is.

What means code does not get deadstripped?

Download All
0 Kudos
Message 3 of 11
(3,310 Views)

Well, the speed difference is not dramatic (not even an order of magnitude ;)) The dramatically simpler variant code is also worth something.

Your non-variant code is also highly optimized. If you would do something that more closely resembles what the variant version does (=search if each element has already be added to the output), it would be much slower, epsecially for large arrays.

 

Interestingly, if you would prepend a long constant string to all you strings, suddenly the variant gets faster. 😉


apapasd1sd wrote:

What means code does not get deadstripped?


See e.g. figure 13 here. Dead code elimination removes code where executing it would no make a difference, e.g. if the output is not used. This typically only happens if you disable debugging, though. You should disable debugging, to eliminate general debugging overhead,

 

Don't underestimate the compiler. Sometimes it is difficult to devise a honest benchmark.

 

0 Kudos
Message 4 of 11
(3,298 Views)

Out of couriosity.

When I create large array like 10000 elements by using initialise array it is stored as continious block in memory?

What If I create array in for loop with auto indexing enabled? Is this also continious block in memory ? 

When I add using functions like insert into aray when app is working I think it is unlike that we still have continious block in memory. Is that true?

And what about variants, how this structore is stored in memory?

 

I found that about memory and LV data

http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/how_labview_stores_data_in_memory/

 

LabVIEW stores variants as handles to a LabVIEW internal data structure. Variant data is made up of 4 bytes. - Could someone explain that to me??

 

0 Kudos
Message 5 of 11
(3,277 Views)

apapasd1sd wrote:

When I create large array like 10000 elements by using initialise array it is stored as continious block in memory?

What If I create array in for loop with auto indexing enabled? Is this also continious block in memory ? 

When I add using functions like insert into aray when app is working I think it is unlike that we still have continious block in memory. Is that true?

...

LabVIEW stores variants as handles to a LabVIEW internal data structure. Variant data is made up of 4 bytes. - Could someone explain that to me??


Numeric arrays are always contiguous in memory, independent on how you create it. The loop where you generate the data can be simplified by using autoindexing. same difference, but less code.

When you use "insert into array", a new copy of the entire array typically needs to be made, because it always needs to be contiguous. Insert into array and delete from array are relatilvely slow because of this.

 

You are not really using variant data, just variant attributes. The variant itself is actually empty in your case. Variant attributes are stored internally as a red-black tree, giving very fast lookup, insert, and delete performance.

 

 

0 Kudos
Message 6 of 11
(3,256 Views)

Thanks, that is answet what I needed 🙂

 

So If I insert into array new copy is made. Lets say I don;t use old one more. When is it relased?

0 Kudos
Message 7 of 11
(3,249 Views)
Solution
Accepted by topic author apapasd1sd

LabVIEW manages the memory for you.

 

However, if you make too many reallocations of evergrowing arrays, you might run out of contiguous memory and thus run out of memory, Memory fragmentation can cause problems.

0 Kudos
Message 8 of 11
(3,241 Views)

Thanks, all is clear now 🙂

0 Kudos
Message 9 of 11
(3,234 Views)

I'd say the Remove duplicates test is flawed, as the test is unlikely to actually remove something. If you set the text to use 2 or 3 decimals you'll get some duplicates to remove.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 11
(3,180 Views)