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.
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.
01-25-2017 04:58 AM - edited 01-25-2017 05:09 AM
Hopefully someone can help me with this :
What optimisations could be made to the following code snippet to improve performance (reduce memory thrashing due to string concatenation etc.)?
This is mainly just for improving/learning more best practices and applying them in the future.
I would like to keep the tags and delimiters easy to change.
The output is an array of strings that look like this:
X:1.0000,2.0000,3.0000,4.0000,5.0000,6.0000;\n Y:0.00,0.10,0.20,0.30,0.40,0.50;
I've scoured the internet and forums for this topic and found a post about preallocating an array of uint8, but can't find it now.
Thanks!
01-25-2017 12:42 PM
Unless you're dealing with huge arrays or need to do this at very high speed (in which case, you should probably rethink other parts of your code and avoid strings entirely if possible), I wouldn't worry about optimising this. However, here's a simplification that uses Array to Spreadsheet String.
01-25-2017 01:15 PM
Why clusters?
01-26-2017 05:39 AM - edited 01-26-2017 05:44 AM
Thanks nathand, that's great. I completely agree - it's just nice to see what methods can be used.
Good call on the array to spreadsheet function, likely more efficient as it's primitive function. The trim looks like it may be less efficient though, as it does a pattern match before trimming?
01-26-2017 05:44 AM
Thanks Alexander, good point.
I originally used clusters as I thought it would look neater with less wires going into the loop, but yours looks just as tidy and more effiecient.