Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Who is that grouch? -or- Fun with functions! Re:(2)

From: joel:neely:fedex at: 5-Oct-2000 8:56

Hi, Allen, Thanks for the help! (Any suggestions for speeding up map?) [allen--rebolforces--com] 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 ] ] ]