[REBOL] Re: Storing a logical condition
From: joel:neely:fedex at: 20-Oct-2003 11:20
Hi, Tim, and all!
My buffer overflowed, but maybe this is still worth posting...
Tim Johnson wrote:
> * Brett Handley <[brett--codeconscious--com]> [031013 16:42]:
>>Like Ingo's observation, it is significantly faster too - significant if you
>>have a million iterations ;^)
>>
>> >> timeit [repeat i 1000000 [do b]]
>> == 0:00:04.387
>> >> timeit [repeat i 1000000 [all b]]
>> == 0:00:02.604
>
> Cool! Who woulda thunk it?
> That's a good tip.
> thnx
> tim
>
Using a block specified as
blk: [dummy = 1]
and a function defined as
fn: func [] blk
I compared the runtimes of
loop reps [] ;; to deduct loop overhead
loop reps blk ;; "in-line"
loop reps [do blk] ;; "do"
loop reps [first reduce blk] ;; "first reduce"
loop reps [fn] ;; "fn"
loop reps [any blk] ;; "any"
loop reps [all blk] ;; "all"
After deducting the loop overhead from all other timings (average of
ten) I calculated the ratio of each relative to the inline case. I
tested with DUMMY equal to 1 and 2 (just in case there was an effect
on ANY or ALL), but found no significant difference. Timings were
done on an Athlon 2400 running wXP, with REPS set to ten million.
I was surprised (and educated) by the result for one version!
version avg time ratio to in-line
------------ -------- ----------------
in-line 1.827 s 100.0%
fn 3.067 s 167.9% ********
any 3.826 s 209.4%
all 3.869 s 211.7%
do 3.998 s 218.8%
first reduce 15.771 s 863.1%
Yep! The winner is the lowly, plain-vanilla function! At least for
this simple case, the fastest way to defer the evaluation of an
expression is simply to make that expression the body of a function
with no parameters!
I guess sometimes we outsmart ourselves! ;-)
-jn-
--
----------------------------------------------------------------------
Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446
Enron Accountingg in a Nutshell: 1c=$0.01=($0.10)**2=(10c)**2=100c=$1