Hi Rebols,

just tried this:

[code]----------------------------------------------------------------------

range: func [start [number!] end [number!] /local result [block!]] [
  result: make block! (end - start + 1)
  for i start end 1 [
    append result i
  ]
]

filter: func ["filter function"
  :f [any-function!] block [block!] /local result [block!]
] [
  result: copy []
  foreach element block [
    if f element [
      append/only result element
    ]
  ]
  result
]

filter-diff: func [
  { filter function
    returns [[... filtered ...] [...unfiltered ...]]}
  :f [any-function!] block [block!] /local result [block!] diff [block!]
] [
  result: copy []
  diff:   copy []
  foreach element block [
    either f element [
      append/only result element
    ][
      append/only diff   element
    ]
  ]
  reduce [result diff]
]

bench: func ["wants to be a benchmark func"
  block [block!] loops [integer!] /local t [time!]
] [
  t: now/time
  loop loops [
    prin #"-" ; this hurts...
    do block  ; this too
  ]
  now/time - t
]

list: range 1 1000

print bench [filter-diff odd? list] 100

print bench [difference/only list filter odd? list] 100

print ""

probe filter-diff odd? probe range 1 20
; >> print mold list: range 1 20
; == [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
; >> print mold filter-diff odd? list
; == [[1 3 5 7 9 11 13 15 17 19] [2 4 6 8 10 12 14 16 18 20]]


[/code]---------------------------------------------------------------------

[Output]--------------------------------------------------------------------

----------------------------------------------------------------------------
------------------------
0:00:06
----------------------------------------------------------------------------
------------------------
0:01:14

[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
[[1 3 5 7 9 11 13 15 17 19] [2 4 6 8 10 12 14 16 18 20]]
>>

[/Output]-------------------------------------------------------------------


There's a BIG PROBLEM:
'filter-diff AND 'filter are waayyy too *slow*

Any suggestions ???


Rebol-as-Rebol-can...

Regards,

Oliver Schaefer ([EMAIL PROTECTED])



Reply via email to