06-16-2017 09:12 AM - edited 06-16-2017 09:18 AM
@TheStrangeQuark wrote:
Is this correct that it only compares the last bit of the int to 1?
AND is a "masking" operation, and since 1 has only the least bit set (all others are zero), ANDing will only leave the single bit that is either set (odd) or not (even). So while the equal operation still compares all bits, almost all are zero. Bit-wise operations on integers are very fast.
A few things to speed your code up:
See how far you get. I'll post my code later for comparison.
06-16-2017 09:27 AM
I'm getting my solution in 9.02 seconds now. It's better but still 2 orders of magnitude slower than you.
06-16-2017 09:44 AM
What's the model of your CPU?
Mine is an older dual Xeon (2x E5-2687W) running at 3.1GHz. Since nothing is parallelized here, it is of course only using one core. I expect a modern I7 to be faster.
06-16-2017 09:48 AM
I'm using an Intel(R) Core i5-4300M @ 2.60 GHz
06-16-2017 12:39 PM - edited 06-16-2017 12:40 PM
OK, here's my version.
(Note that you only need to do the =1 check for even inputs. (3n+1 can never be 1.)
An here's my typical timing result:

There are probably faster ways to do all that. 😄
06-16-2017 12:45 PM
Would you mind saving it for LabVIEW 2015? I'm a bit ol' fashioned
06-16-2017 02:17 PM
@TheStrangeQuark wrote:
Would you mind saving it for LabVIEW 2015? I'm a bit ol' fashioned
Try this...
06-16-2017 02:22 PM - edited 06-16-2017 02:48 PM
Of course I made a few quick and simple modifications and it gets the same result now in well under 50ms. 😮
There is still a lot of slack left. Try it! 😄

06-17-2017 03:16 PM - edited 06-17-2017 03:30 PM
For completeness, here's my faster versions. See if you figure out the code. It is very simple! 😉
(Note that it also works correctly if you delete the 1D array from the toplevel code and leave the array inputs/outputs unwired at the subVI, it is just slower :))
It does 1M in under 50ms, 20M in about a second, and 100M in about 5 seconds on my slow laptop.(I7-5600U CPU @ 2.60GHz)
(If you try to go much higher (e.g. 1G), you'll run out of memory in 32bit LabVIEW)
(It does not use any parallelization. See if you can improve it significantly, i.e. more than 5% :D)
06-22-2017 10:28 AM
For reference, I wonder if some of you could get speed results on various other CPU models, e.g. for 20M or 100M. For example, I would be curious about AMD vs Intel, for example.