Hi, Allen,

Thanks for the help!  (Any suggestions for speeding up map?)

[EMAIL PROTECTED] wrote:
> 
> >
> >     >> iota: function [n [integer!]] [r i] [
> >     [    r: copy []
> >     [    i: 0
> >     [    while [i < n] [append r i: i + 1]
> >     [    r
> >     [    ]
> 
> iota: function [n [integer!]][r i][
>     r: copy []
>     repeat i n [append r i]
> ]
> 
> Using the 'repeat native is quicker. (by about 1 sec per 1000
> iterations on my machine).
> 

Motivated by your comment, I ran a quick benchmark test:

    >> bloop/run 50000
    repeat:  8   1
      loop:  25      3.125
     while:  26      3.25
       for:  30      3.75

where the second column is raw times (on a slow box) and the
third column is times relative to the  repeat  version.  I'd
guess that the performance hit for  loop  and  while  is in
the high-level handling of the counter; a quick look at the
source for  for  explains its 4th place showing -- he's a
busy little beaver!

-jn-


PS:  The QAD benchmark code is below, if anyone's interested:

REBOL []

bloop: make object! [
        t0: t1: t2: t3: t4: now/time
        dsec: func [b [time!] e [time!]] [
                e: e - b
                e/hour * 60 + e/minute * 60 + e/second
        ]
        run: func [n [integer!] /local b i] [
                t0: now/time
                        b: copy []
                        repeat i n [append b i: i + 1]
                t1: now/time
                        b: copy []
                        i: 0
                        loop n [append b i: i + 1]
                t2: now/time
                        b: copy []
                        i: 0
                        while [i < n] [append b i: i + 1]
                t3: now/time
                        b: copy []
                        for i 1 n 1 [append b i]
                t4: now/time
                print [
                        "repeat: " t0: dsec t0 t1 tab t0 / t0 newline
                        "  loop: " t1: dsec t1 t2 tab t1 / t0 newline
                        " while: " t2: dsec t2 t3 tab t2 / t0 newline
                        "   for: " t3: dsec t3 t4 tab t3 / t0
                ]
        ]
]

Reply via email to