08-11-2015 10:22 AM
08-11-2015 10:23 AM
@James.M wrote:
@Hooovahh wrote:
Yeah I've heard it is actually faster to perform a reverse 1D array, add at the end, reverse 1D array again, rather than add at the front. I personally haven't tested this, and if this were the case I'm not sure why the compiler wouldn't just do it this way behind the scenes.
Gosh, this whole time I've tried so hard to stay away from the Reverse 1D function because I assumed it had more overhead than just creating the array the right way from the start. I guess I'm reminded again what assuming does.
Edit: It looks like this is not the case... I get 125x iterations with the above code, but with the Reverse 1D Array nodes, it slows down considerably to where the first method is anywhere from 150x to 280x faster.
Hi James,
Why to have reverse array in every iteration???
Just put it at very last when array has been build.. I am sure this will fasten code then that you tested before..
08-11-2015 10:26 AM
Oh, I had read Hoover's " I've heard it is actually faster to perform a reverse 1D array, add at the end, reverse 1D array again" as faster at each iteration. Doing it once at beginning and once at the end would obviously be faster, but usually when I'm adding a value at the beginning of the array, it's a one-time thing instead of 100,000 times in a row.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-11-2015 10:28 AM
James, don't you want to be comparing adding an element to the start of an array to your reverse array method? Right now I think you're comparing adding elements to the end of an array to the reverse 1D array method.
08-11-2015 10:30 AM
DCKAN wrote:
Even if we know array size very before we build, instead of pre allocating space for array, I would prefer this function if only build is required.
That is precisely the situation for a FOR loop with Autoindexing tunnels. This is, by far, the most efficient way to build your arrays, time and memory.
Plus these benchmark code are completely off. You should be running a set number of loops and measure the time difference. If I find some time, I'll try to set up a better benchmark.
08-11-2015 10:49 AM
@crossrulz wrote:
Plus these benchmark code are completely off. You should be running a set number of loops and measure the time difference. If I find some time, I'll try to set up a better benchmark.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
08-11-2015 10:58 AM
Here is my benchmark. Array size = 100000. While loop prepend = ~3 seconds. While loop append = ~0.3 seconds. For loop = 1.3 milliseconds. Reverse Array = ~35 nanoseconds.
Lynn
08-11-2015 11:33 AM
@James.M wrote:
Oh, I had read Hoover's " I've heard it is actually faster to perform a reverse 1D array, add at the end, reverse 1D array again" as faster at each iteration. Doing it once at beginning and once at the end would obviously be faster, but usually when I'm adding a value at the beginning of the array, it's a one-time thing instead of 100,000 times in a row.
Yeah I get your point, and I see your code, it does seem to controdict what I've heard about the reverse 1D array, not sure why. Someone from NI would need to chime in for an explaination.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord