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

[REBOL] Re: cyclic values

From: joel:neely:fedex at: 29-Sep-2002 21:26

Hi, Carl Carl Read wrote:
> > ... > > Indeed. But it suggests a way I haven't seen posted... > > >> colors: [red green blue] > == [red green blue] > >> forever [print color: colors/1 remove append colors color] > red > green > blue > red > green > blue > red > green > blue > red > green > blue > red > green > blue > red > (escape) > > Has the advantage of no extra words being needed. The > disadvantages being the contents of the colors block is > cycling, (might or might not matter), and it may be slower... > It should have a consistant speed though. Comments Joel? >
Don't try this at home kids! ;-) Cycling the values within the block does matter; there's much more memory management overhead. Using the same benchmarks as in the earlier comparison, the block-cycling version takes 4 to 5 times as long as the modulus approach for 3-10 elements. In addition the overhead grows with the length of the block being cycled: bruteforce: func [n [integer!] c [integer!] /local t b v] [ b: make block! n repeat i n [insert tail b i] t: now/time/precise loop c [ remove append b v: b/1 ] t: to-decimal now/time/precise - t ] behaves as:
>> for i 10 200 10 [print [i bruteforce i 500000]]
10 24.99 20 22.91 30 29.49 40 25.27 50 23.45 60 27.19 70 25.76 80 29.22 90 25.98 100 29.6 110 26.75 120 30.05 130 27.24 140 28.89 150 29.83 160 30.71 170 30.97 180 31.2 190 33.18 200 32.9 The raggedness likely indicates intermittent gc operations; the trend is definitely upward as the block length grows. -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]