11-08-2010 12:54 PM
Have a large array of Int32 (~500,000 elements).
Each Int32 needs to be parsed into two Int16 arrays: Array 1 is the first 12 bits of the Int32, Array 2 is the second 12 bits of the Int32.
The method I am using (see attached) works just fine but it is taking a lot of time to run (on a relatively slow, embedded CPU).
Does anyone have an idea how to make this run faster?
Solved! Go to Solution.
11-08-2010 01:42 PM
The best format in which to post an image is PNG (JPEG and GIF are ok, too). Please do not embed an image in an RTF or Word document.
Here's one quick approach, haven't tested the timing but I suspect it's faster. There's probably room to optimize further.
11-08-2010 01:44 PM
Using boolean operations on numbers appears to be quite a bit faster: 42 ms vs 280 ms for 1000000 point arrays. See the image below.
Also, when I duplicated the code in your image I did not get the results you described in your post. Please post images as .png files. They can be embedded rigtht into the post using the insert/edit image button (looks like a tree).
Lynn
11-08-2010 01:45 PM
Glad I refreshed. That was exactly what my snippet looks like. And agreed, I have not benchmarked it. And not sure there is a more optimal way of doing it.
11-08-2010 02:57 PM
Thanks everyone - that works great.
11-08-2010 03:00 PM
The polymorphism of boolean inputs is one of those little things which people often miss when they are learning to use LV. They can take both scalar and array inputs.
Lynn
11-08-2010 07:27 PM - edited 11-08-2010 07:27 PM
Since you have large arrays, the above methods allocate a few extra arrays, possibly slowing you down.
Here's a version that uses fewer array allocations. You might want to benchmark a few versions....
11-09-2010 05:05 AM
Excellent - thanks I'll give it a try!
11-09-2010 10:36 AM
@red Sox Fanatic wrote:
Excellent - thanks I'll give it a try!
Not that you needed more ways to solve this problem, but lots of us on this board are curious about performance and I had a few minutes to throw together a VI to test the timing of a few approaches suggested here, as well as two variations of an additional approach that I like (shown here). The basic conclusion is that they're all pretty close on my machine (LV 2009). Splitting a 1-million element array, averaged over 50 times, the approach with 2 ANDs was 20ms. Using a FOR loop was 21ms. Using a pair of shifts (shown below) was 17ms. A variation of this, with a typecast, was much slower, at 35.5ms.
11-09-2010 10:56 AM