Hi, Alan,

alan parman wrote:
> 
> Re: Improving function speed (no code)
> 
...
>
> I still can't get rid of one 'append though ...
> ...
>                 s: j: i: 0
>                 state: make block! 256
>                 loop 256 [append state s s: s + 1]
> ...
> 

It *can* be sped up slightly (saving a millisecond a month
somewhere ;-)

    b: make block! n  i: 0           t0a: now/time/precise
    loop n [append b i i: i + 1]     t0b: now/time/precise

    b: make block! n  i: -1          t1a: now/time/precise
    loop n [append b i: i + 1]       t1b: now/time/precise

    b: make block! n  i: -1          t2a: now/time/precise
    loop n [insert tail b i: i + 1]  t2b: now/time/precise

    print [t0b - t0a t1b - t1a t2b - t2a]

The first version is similar to yours, the second eliminates
the doubled use of the counter, and the third uses the well-
known APPEND ==> INSERT TAIL optimization.  Timing the above
five times for N of one million yields these results:

    0:00:04.687 0:00:04.507 0:00:02.113
    0:00:04.707 0:00:04.547 0:00:02.143
    0:00:04.677 0:00:04.526 0:00:02.113
    0:00:04.687 0:00:04.536 0:00:02.113
    0:00:04.656 0:00:04.586 0:00:02.113

Most of the savings, as expected, results from the second
optimization, but avoiding the "double-dipping" does have
a measurable value.

-jn-
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to