02-22-2016 12:53 PM
@bsvare wrote:Didn't spend any longer this time, though, it's not the most optimized. Certinally doesn't work well with the bonus points.
My initial implementation was very similar to yours, but isn't nearly fast enough for the bonus. The bonus though is far more difficult than I thought it would be.
I've been playing around for about an hour trying to come up with something that will solve the bonus in a couple of seconds. No luck yet! I'm curious to see if anyone will get the bonus.
02-22-2016 02:39 PM - edited 02-22-2016 02:40 PM
Here's my brute force attempt. Yes it is slow but avoids allocating intermediary arrays and simplifies a few other things.
02-22-2016 03:04 PM
It's actually an order of magnitude faster doing the boolean sub-arrays, so yes, my initial assumption was wrong.
02-22-2016 03:18 PM
@altenbach wrote:It's actually an order of magnitude faster doing the boolean sub-arrays, so yes, my initial assumption was wrong.
Yea, your first solution was almost identical to mine (I didn't use DVR), but it was slow. I've been playing around with using an array if integers instead of an array of boolean. (Boolean = 1 bite, using integers I can theoretically toggle bits instead of the first bit in each byte). I haven't gotten it working yet though. I'll play with it tomorrow - I'm out of "goof off time" for the day 🙂
If anyone has any other ideas for optomization, I'm open. If a Python solution can execute in 1.5 seconds, surely we can do it in LabVIEW...!
02-22-2016 03:36 PM
@BowenM wrote:
@altenbach wrote:It's actually an order of magnitude faster doing the boolean sub-arrays, so yes, my initial assumption was wrong.
Yea, your first solution was almost identical to mine (I didn't use DVR), but it was slow. I've been playing around with using an array if integers instead of an array of boolean. (Boolean = 1 bite, using integers I can theoretically toggle bits instead of the first bit in each byte). I haven't gotten it working yet though. I'll play with it tomorrow - I'm out of "goof off time" for the day 🙂
If anyone has any other ideas for optomization, I'm open. If a Python solution can execute in 1.5 seconds, surely we can do it in LabVIEW...!
But even if we could operate on 64bits concurrently (except for some edge cases which would need a bit more code), it would not speed things up sufficiently to account for the difference. I think we need to fundamentally change the approach....
02-23-2016 09:57 AM - edited 02-23-2016 09:58 AM
@altenbach wrote:
But even if we could operate on 64bits concurrently (except for some edge cases which would need a bit more code), it would not speed things up sufficiently to account for the difference. I think we need to fundamentally change the approach....
I guess that makes sense. It would speed things up, but I'm not sure it would drop us down to the 2 second range. I just attempted a solution that stored an array of just the lights that were "On". Searching the array for a specific light was (unsurprisingly) too slow once the array got larger than a few thousand entries. I'll keep thinking about it...
02-23-2016 02:02 PM
Bonus Points Round: 185 ms for the bonus file on my computer.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
02-23-2016 02:32 PM
Cool!
I actually made a very similar one yesterday, including the sorting and +1 on the off times, but there was a bug and I had no time to troubleshoot later.
I think there is still some slack left, though. 😄
02-23-2016 02:58 PM - edited 02-23-2016 03:01 PM
@altenbach wrote:I think there is still some slack left, though. 😄
Here's a 5 minute rewrite that gives the same result but is about 20% faster (and significantly simpler code ;))
It seems parallelization makes little difference.
It is your code verbatim and I have not verified that it is actually correct. 😄
02-23-2016 03:33 PM
There was about a 10ms improvement using parallelism in my code (from 195 to 185). Minor, but still notable.
Unless something has improved greatly, I thought the auto indexing output tunnels were extremely poor on memory efficiency . I thought it had to recreate the output array each time something was added. Thus why I attempted to do the value updating into an pre created array. Assuming the best optimization of the arrays, it should be able to determine the final array size and index it properly, or do exactly what I explicitely did.
As for the min/max vs array sort, My first attempt was to get the two values and do a compare what is greater, and then use the Swap value primitive. However, I found that sorting the array and then just getting the two values to be faster. I didn't test min/max. That may be the sole cause of the 20% speed increase.
As for the code being right, I did verify it produced the same number of lit bulbs as all three problems would using the old methods.So I'm assuming it's right.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books