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

[REBOL] if/else vs. either

From: joel::neely::fedex::com at: 23-Jul-2001 18:04

Hi, Allen (and all) <note> I've been out camping in the mountains for a week, so I'm still playing catch-up on megabytes of email. If I fail to reply to something, please put it down to oversight rather than rudeness or disinterest! </note> Following up on an idea from Allen, I ran the following quick- and-dirty tests with mildly interesting (but not too surprising) results. Taking some relatively trivial block, such as deed: [a: a + 1] or even deed: [a: 17] we can evaluate it a few hundred million times in different ways to discover the following approximate relative timings. (Due to coarse-grained timing jitter and overall system workload, results are rounded to the nearest 10%.) Relative Overhead Expression Required ---------- -------- do deed 100% if true deed 130% either true deed [] 150% either false [] deed 150% if/else true deed [] 170% if/else false [] deed 170% The timing calculations subtracted the base workload before figuring the ratios, so that the comparison is just for the control functions themselves. Different numbers of cycles and different expressions will vary the timings somewhat, but these figures (+/- 10%) appear to be relatively typical. Conclusion: Use EITHER instead of IF/ELSE unless writing for people who are addicted to TLTMNBN! ;-) -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com