11-02-2014 07:53 AM
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.
Solved! Go to Solution.
11-02-2014 08:49 AM - edited 11-02-2014 08:52 AM
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
11-02-2014 10:11 AM
Here it is.
What means code does not get deadstripped?
11-02-2014 10:38 AM - last edited on 08-19-2024 02:35 PM by Content Cleaner
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.
11-02-2014 11:48 AM - last edited on 08-19-2024 02:34 PM by Content Cleaner
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
https://www.ni.com/docs/en-US/bundle/labview/page/how-labview-stores-data-in-memory.html
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??
11-02-2014 12:49 PM - edited 11-02-2014 12:50 PM
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.
11-02-2014 01:00 PM
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?
11-02-2014 01:11 PM
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.
11-02-2014 01:20 PM
Thanks, all is clear now 🙂
11-03-2014 06:25 AM
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