I'd expect that for two reasons.

The first is that all array keys are interred strings (names) so integers need 
to first be converted to strings and then hashed into a name and then hashed to 
the slot in the arrays hash table.

The second is that byte based version is essentially using a byte sequence as a 
bit set - each setting of a byte in the set is about as close as you get to a 
truly atomic (in the sense of using '1' instruction) as you can get in LC.

It is what you would do in C if you couldn't be bothered using bit operations 
to manipulate individual bits in machine words (which would be substantially 
faster again - as you would be touching 1/8th of the memory).

Warmest Regards,

Mark.

Sent from my iPhone

> On 6 Aug 2018, at 20:24, Mark Wieder via use-livecode 
> <use-livecode@lists.runrev.com> wrote:
> 
> Interesting. I tried a variation using arrays, and it's three times slower 
> than yours.
> 
> function get_primes pN
>   local tMroot, tPrimes, tIsItPrime
> 
>   if pN < 2 then return empty
>   if pN = 2 then return 2
>   put trunc(sqrt(pN)) - 1 into tMroot
> 
>   repeat with i=1 to pN step 2
>      put 1 into tIsItPrime[i]
>   end repeat
> 
>   repeat with i = 3 to tMroot step 2
>      if tIsItPrime[i] is empty then next repeat
>      repeat with j = i^2 to pN step i
>         delete variable tIsItPrime[j]
>      end repeat
>   end repeat
> 
>   return the keys of tIsItPrime
> end get_primes
> 
> -- 
> Mark Wieder
> ahsoftw...@gmail.com
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to