LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fun benchmark: modify last column in an 2D array (I almost guessed wrong)

Solved!
Go to solution

I made a quick array modification SubVI to modify the last column.

Secondly, why not optimize this code slightly? And what is optimization without a benchmark?

 

Task, multiply last column with 1.000001. Do this 1 000 000 times.

paljacob_0-1599484841370.png

 

Method 1: use array functions. Method 2: use in place array functions

 

paljacob_1-1599485200897.png

 

 

So in my head "Method 2" should be the best one in most if not all input examples.

paljacob_2-1599485314769.png

 

What "Method 1" 25 times quicker?

Hmmm, I remind myself again I need to stop doing this small optimizing tasks 😄

Optimizing before finding something that actually matters to optimize, is not the way to go if you want to get more done.

 

So, then at last, what is optimizing without turning off debugging?

paljacob_3-1599485621938.png

 

Wow, in-place method won!!!!!!! 😅 

Message 1 of 20
(1,673 Views)

What about a 3rd method? Just Index out the last last column, mulitply and Replace Array?

Replace last column.png

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

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 20
(1,661 Views)

Hi paljacob,

 


@paljacob wrote:

Task, multiply last column with 1.000001. Do this 1 000 000 times.


Reading this sentence word by word gives this result:

This is a 1000 times faster… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 20
(1,617 Views)

@GerdW wrote:

Hi paljacob,

 


@paljacob wrote:

Task, multiply last column with 1.000001. Do this 1 000 000 times.


Reading this sentence word by word gives this result:

This is a 1000 times faster… 😄


 

Hehe, it had to come 😄

https://www.youtube.com/watch?v=Ct-lOOUqmyY

0 Kudos
Message 4 of 20
(1,585 Views)

@Yamaeda wrote:

What about a 3rd method? Just Index out the last last column, mulitply and Replace Array?

Replace last column.png


Ok, had to add it to the test, Method 3. Slightly modified to compare similar code.

paljacob_0-1599550263653.png

 

With debugging on this Method 3 is the winner.

paljacob_1-1599550403143.png

 

But turning debugging off, Method 2 still wins:

paljacob_2-1599550464532.png

 

Thanks 🙂

Message 5 of 20
(1,581 Views)

Hi paljacob,

 


@paljacob wrote:


 

paljacob_0-1599550263653.png

With debugging on this Method 3 is the winner.

 

But turning debugging off, Method 2 still wins


Please read/watch the tutorials/presentations given by Christian Altenbach on "good benchmarking"!

This whole test is flawed:

  • don't use locals to forward large datasets
  • right now you also benchmark the time needed to read the data from the locals and the time needed to store the result in an indicator

Try to time only each "core" loop!

 

What's the point of manipulating the same array column a million times when you only keep the result of the last iteration? Seems a quite senseless operation!

All you do is testing LabVIEWs ability to index/edit array elements spread across a large memory block: arrays are stored row-wise in memory…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 20
(1,576 Views)

I'd use an IPE structure like this:

Replace row.PNG

EDIT: Oops probably need to switch dimension to 1...

Replace row 2.PNG

Message 7 of 20
(1,573 Views)

I never used IPE with split array before, so thanks for sharing!

 

I guess for many of these methods, the very small data set is not fair to the method, but it shows how different it can be.

 

So with debugging on:

paljacob_1-1599554749296.png

 

And debugging off:

paljacob_0-1599554723255.png

 

Crazy how Method 4 costs like 400 times more than method 2.

0 Kudos
Message 8 of 20
(1,555 Views)

@paljacob wrote:

I never used IPE with split array before, so thanks for sharing!

 

I guess for many of these methods, the very small data set is not fair to the method, but it shows how different it can be.

 

So with debugging on:

paljacob_1-1599554749296.png

 

And debugging off:

paljacob_0-1599554723255.png

 

Crazy how Method 4 costs like 400 times more than method 2.


As mentioned, your benchmark is not valid.

 

I get 40 ms on my method, 1.5 us if I put the locals outside the structure.

 

I get:

Benchmark replace row.PNG

And:

Benchmark replace row (Debugging off).PNG

 

OOPS: Probably messed that up... Anyway, with the locals in the loop, you won't get fair results.

 

0 Kudos
Message 9 of 20
(1,551 Views)
Solution
Accepted by topic author paljacob

First, thank you for your feedback! 

Ok, I must be blind or something. I can't see what you see 🙂

Could you share your .vi? I don't understand how you managed to get your results.

 

GerdW: All methods are performing the same task right? Do you agree? Anyway, I just had to test it 🙂

FYI: doing the same task 1 000 000 times is just to get a more measurable benchmark on a function like this.

 

So to challenge your statements I modified the benchmark to run methods 1 to 4 without reading and writing to inside the benchmark, but also added a copy where locals are used and writing to the indicator is included. First, as this read/write is only done once during the benchmark, it does not matter too much. Secondly, it shows that it does not change the ranking between the methods (but debugging on/off changes ranking).


Debugging on:

image.png

Debugging off:

image.png

 

Picture of the benchmark code:

image.png

0 Kudos
Message 10 of 20
(1,510 Views)