Select VS path access
[1/4] from: robert:muench:robertmuench at: 9-Nov-2002 16:41
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
The only difference I see is that the path method results in a value and
that SELECT returns a series. Is this more? Robert
[2/4] 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 ]
[3/4] from: janko:mind-nest at: 9-Nov-2002 20:41
Hi all!
> RMM> Hi, is there a difference (speed?) between the following two methods?
I made the folowing...
b: [ a "leter a" b "leter b" c "leter c" d "leter d" ]
a: func [ x ][ start: now/time/precise loop 100000 [ do x ] print
now/time/precise - start ]
and then tested with (>> is from rebol console)
>> a "b/d"
0:00:01.1
>> a "b/a"
0:00:00.99
>> a "select b 'd"
0:00:01.1
>> a "select b 'a"
0:00:00.99
You can see that in hundred thousand repetitons select and path spend
exactly same time
----------------------------------------------------------------------------
------------
There is one difference betwen this two, that I know off.
if you have block like
a: [ "a" "leter a" "b" "leter b" ]
you cant use path
>> print a/"a"
** Syntax Error: Invalid path -- a/
>> print a/a
** Script Error: Invalid path value: a
but you can use select...
>>print select a "a"
leter a
This is often used in rebol databases where you use select to retrieve the
record by the key.
[
....
key002
[ "ksadfk" "dfkasdf" "adfa"]
key003
[ "dfkasdf" "adfa" "ksadfk"]
.....
]
I hope this helped!
:janko
url: [ http://www.mind-nest.com ]
[4/4] from: robert:muench:robertmuench at: 10-Nov-2002 14:51
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 6>>
> to-decimal now/time/precise - t
> == 9.99
Hi, I think I have to memorize the speed check code snippet ;-)).
> ... so it appears that SELECT is faster for small cases, but
> doesn't scale up as well.
Ok, thanks.
> Both return a value, rather than a subseries.
Ups, yep you are right. I mixed it up. Robert
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted