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

[REBOL] Re: Series comparison techniques

From: greggirwin:mindspring at: 14-Aug-2003 9:09

Hi Ashley, AT> search-series: func [series [series!] operator [string!] value] [ AT> clear rowids AT> switch operator [ AT> "=" [operator: :equal?] AT> "<>" [operator: :not-equal?] AT> "<" [operator: :lesser?] AT> ">" [operator: :greater?] AT> "<=" [operator: :lesser-or-equal?] AT> ">=" [operator: :greater-or-equal?] AT> "like" [operator: :find] AT> ] Did you consider passing the operators in directly as the argument, rather than passing a string and mapping it? Re: FIND AT> ...returned results in .015, .063 and .59 seconds respectively. Which got me AT> thinking about *how* REBOL could do this given: AT> 1) The series is not sorted AT> 2) Values are not unique AT> 3) Runtime increases at a lesser rate than data volume Natives, like FIND and SELECT, are always preferred for performance reasons. If you look at the line inside your loop: if operator series/:pos value [insert tail rowids pos] You're calling IF on every iteration. Even if it's a native, that's still a function call with overhead. OPERATOR will also require a call, so that's two. Then SERIES/:POS has to be evaluated, which means path evaluation, bounds checking, and lookup. Finally VALUE has to be evaluated as well. And while REPEAT is pretty efficient, it's not going to compete with a native machine code loop. I still find it instructive to test various constructs to see how fast they are. Sometimes things will surprise you. -- Gregg