LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert boolean array to an numeric count array


@Hooovahh wrote:
Hope you don't mind but I found orders of magnitude improvement by removing the for loop, and replacing the while loop with a for loop.  In my test running the code 10000000 times took about 8459ms to execute, but after these two changes took 2ms.  I tried a few other ideas but couldn't come close to this.  Oh automatic error handling and debugging was turned off for the test.


Your benchmark is flawed because the inner FOR loop is folded.

What is the size of the boolean array input?

0 Kudos
Message 11 of 25
(1,206 Views)

@altenbach wrote:

Your benchmark is flawed because the inner FOR loop is folded

 



I see no difference between the while loop and the for loop implementation with an initialized array of size 10,000,000.  However Will's code doesn't have the conversion to 1's and -1's so his code runs faster.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 12 of 25
(1,191 Views)

altenbach wrote:


Your benchmark is flawed because the inner FOR loop is folded.

What is the size of the boolean array input?


My boolean array size was around 15 I forgot to set the default values.  You say my inner FOR loop is folded?  I only have one for loop is that the one you are refering too?  I'll try again with randomized data (the same randomized data for the other method).

 

EDIT: With randomized data I still get large improvements over the original I forgot to test Wills method against it.

0 Kudos
Message 13 of 25
(1,190 Views)

For a boolean array input of 10M and folding eliminated, both aputman's and hoovah's code are about 800ms, while my variant (not shown) takes 150ms. There is room for improvment, guys! 😄

0 Kudos
Message 14 of 25
(1,188 Views)

@altenbach wrote:

For a boolean array input of 10M and folding eliminated, both aputman's and hoovah's code are about 800ms, while my variant (not shown) takes 150ms. There is room for improvment, guys! 😄


That's why you are the champion.  Smiley Wink

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 15 of 25
(1,183 Views)

another one, just for the fun, nothing else.

 

SR1.png

0 Kudos
Message 16 of 25
(1,178 Views)

@altenbach wrote:

For a boolean array input of 10M and folding eliminated, both aputman's and hoovah's code are about 800ms, while my variant (not shown) takes 150ms. There is room for improvment, guys! 😄


Alright Mr. Champion see if you can beat this (you probably can).  10M booleans aptuman's version 470, Wills 797, mine 72, your milage may vary. (Case 3 in this structure)

 

EDIT:  I realized I cheated a little, I have 80% TRUE and 20% FALSE in my boolean array, setting it to 50% does make it take longer.

0 Kudos
Message 17 of 25
(1,164 Views)

My solution was a much simpler modification and was based on the fact that the conditional tunnel is not well optimized at guessing the final allocation size. 😉

0 Kudos
Message 18 of 25
(1,148 Views)

@altenbach wrote:

My solution was a much simpler modification and was based on the fact that the conditional tunnel is not well optimized at guessing the final allocation size. 😉


Notice that my solution also didn't use the conditional tunnel (I'm aware of the not ideal performance too), and the loop does not iterate for every element in the array, but instead loops for every transition from TRUE to FALSE or FALSE to TRUE.

 

Are you ready to post your solution yet?  Have I come close enough to yours in terms of speed?

0 Kudos
Message 19 of 25
(1,145 Views)

I haven't really tested it, but here's what I came up with. 😄 I think it is slightly faster than yours (at least on 2013). 😉

(The select node and add could be replaced by a case structure containing +1 or -1, resp. Does not seem to really make a difference) 

 

According to some casual testing, I think it performs correctly.

 

 

0 Kudos
Message 20 of 25
(1,139 Views)