valueDiff for arrays?
Alex Tweedly
alex at tweedly.net
Mon Aug 6 04:49:52 EDT 2018
arrays are hashed - even if quickly, while byte chunks are constant time.
So replace both uses of the array np with a byte chunk.
i.e.
if byte i of np = "n" then next repeat
...
put "n" into byte j of np
Takes about 40% off the time.
-- Alex.
On 06/08/2018 03:36, Richard Gaskin via use-livecode wrote:
> Mark Waddingham wrote:
>
> > Richard wrote:
> >>
> >> Thinking about performance, I wonder if there's anything from some of
> >> the changes that have boosted PHP 7's performance so far above its
> >> earlier versions which may be relevant for LC:
> >>
> https://www.reddit.com/r/PHP/comments/3q2brz/how_is_php_7_twice_as_fast/
> >
> > I'd actually be really interested in a direct speed comparison between
> > exactly equivalent operations in PHP7 and LC.
>
> Geoff Canyon and I corresponded on this back in March. I don't think
> he'll mind me sharing some of the relevant parts of his test:
>
> ------------------- from GC ----------------------------------------
>
> on mouseUp
> put the long seconds into T
> repeat with c = 1 to 10
> get get_primes(10000000)
> end repeat
> put "Found" && the number of lines in it && "primes in" && the long
> seconds - T && "seconds"
> end mouseUp
>
> function get_primes n
> if n < 2 then return empty
> if n = 2 then return 2
> put trunc(sqrt(n)) - 1 into mroot
> repeat with i = 3 to mroot step 2
> if np[i] > 0 then next repeat
> add 1 to p[i]
> repeat with j = i^2 to n step i
> add 1 to np[j]
> end repeat
> end repeat
> put 2 & cr & the keys of p into R
> sort lines of R numeric
> repeat with i = mroot + (mroot + 1) mod 2 to n - 1 step 2
> if np[i] is empty then put cr & i after R
> end repeat
> return R
> end get_primes
>
> And that takes about fifteen minutes to run on my 2013 MacBook Pro,
> where the slowest performer he's working with takes less than 30
> seconds, and PHP 7 runs in under 7 seconds. Any ideas where I'm
> deviating in my implementation compared to his? Here's the latest
> version of his test that I found:
>
> https://blog.famzah.net/2016/09/10/cpp-vs-python-vs-php-vs-java-vs-others-performance-benchmark-2016-q3/
>
>
> -----------------------------------------------------------------
>
More information about the use-livecode
mailing list