[REBOL] Re: Select VS path access
From: joel::neely::fedex::com at: 9-Nov-2002 12:10
Hi, Robert,
Robert M. Muench
wrote:
> Hi, is there a difference (speed?) between the following two methods?
>
> >>Test: [a 1 b 2 c 3]
> >>Test/a
> == 1
> >>select Test 'a
> == 1
>
A quick test ...
blk: make block! 200
for i 0 99 1 [insert tail blk to-word join "a" i insert tail blk i]
... constructs ...
>> blk
== [a0 0 a1 1 a2 2 a3 3 a4 4 a5 5 a6 6 a7 7 a8 8 a9 9 a10 10 a11 11
...
... which we can search with ...
t: now/time/precise
loop 1000000 [v: blk/a0]
to-decimal now/time/precise - t
== 9.99
t: now/time/precise
loop 1000000 [v: blk/a49]
to-decimal now/time/precise - t
== 63.76
t: now/time/precise
loop 1000000 [v: blk/a99]
to-decimal now/time/precise - t
== 125.07
... versus ...
t: now/time/precise
loop 1000000 [v: select blk 'a0]
to-decimal now/time/precise - t
== 7.97
t: now/time/precise
loop 1000000 [v: select blk 'a49]
to-decimal now/time/precise - t
== 64.1
t: now/time/precise
loop 1000000 [v: select blk 'a99]
to-decimal now/time/precise - t
== 129.68
... so it appears that SELECT is faster for small cases, but doesn't
scale up as well.
> The only difference I see is that the path method results in a value and
> that SELECT returns a series. Is this more? Robert
>
Both return a value, rather than a subseries.
>> blk/a0
== 0
>> select blk 'a0
== 0
Perhaps you were thinking of FIND ??
-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 ]