Re: find_from and match_from

new topic     » goto parent     » topic index » view thread      » older message » newer message

CChris wrote:
> 
> Igor Kachan wrote:
> > 
> > Matt Lewis wrote:
> >  
> > > I've put a feature request on sourceforge for find_from and match_from:
> > > <a
> > > href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1684321&amp;group_id=182827&amp;atid=902785">http://sourceforge.net/tracker/index.php?func=detail&aid=1684321&group_id=182827&atid=902785</a>
> > > 
> > > Text:
> > > "Add two built-in functions, find_from and match_from, which work similar
> > > to
> > > find and match, but add a third parameter, which specifies the place in
> > > the
> > > sequence to begin looking.
> > > 
> > > If found or matched, the index of the find or match is returned, or zero,
> > > if not found or matched to the end of the sequence.
> > > 
> > > This has already been implemented in ooeu (<a
> > > href="http://sf.net/projects/ooeu">http://sf.net/projects/ooeu</a>),
> > so</font></i>
> > > this is a matter of determining if we want this in Euphoria, not the
> > > feasibility or requesting resources for development."
> > > 
> > > 
> > > Since this is already developed (though not documented)in ooeu, we
> > > basically
> > > 
> > > need to decide if this should go into euphoria or not.
> > > 
> > > Matt
> > 
> > Hi Matt,
> > 
> > It seems to be very simple to implement this feature
> > just in some library and do not touch 4 different
> > versions of interpreters, translators, binders
> > with their docs etc etc :
> > 
> > }}}
<eucode>
> > -- not tested
> > global function find_from_to(integer N, integer L, object a, sequence b)
> >           L = find(a, b[N..L])
> >        if L then return L-1+N
> >        else return L
> > end function
> > 
> > global function match_from_to(integer N, integer L, sequence a, sequence b)
> >           L = match(a,b[N..L])
> >        if L then return L-1+N
> >        else return L
> > end function 
> > </eucode>
{{{

> > 
> > Any one can redefine the standard find() and match() as these
> > above function just now (ok, after testing and correction)
> > and use them.
> > 
> > You do know I'm very and too conservative and lazy guy,
> > so just my $0.02   smile
> > 
> > Regards,
> > Igor Kachan
> > kinz at peterlink.ru
> 
> Very easy and VERY SLOW, because you create a slice just to specify a start
> and end point, and destroy it on return. Do this a few hundred times in a
>  loop...
> 
> So the idea is indeed to "touch 4 different
> > versions of interpreters, translators, binders
> > with their docs etc etc"
> so that you can more sensibly just change the
> bounds of the for loop used internally to find something in a sequence, 
> and set them to N and L, not just 1 and length(s). Hence, find_from() and 
> friends will be faster than find() if N is large, instead of being slower as
> your code is.

It all depends on ...

function find_from_to(integer N, integer L, object a, sequence b)
     L=find(a,b[N .. L])
     if L then
       return L-1+N
     else
       return L
     end if
end function

sequence p,q,z
p=repeat(10000,9)
q=repeat({}, 10000)

for i=1 to length(q) do
    q[i] = rand(p)
end for    
 
 z=rand(p)

atom T, ok
T=time()
for i=1 to 3000 do
ok = find(z, q)
end for
T=time()-T
? T

T=time()
for i=1 to 3000 do
ok = find_from_to(1,10000,z,q)
end for
T=time()-T
? T

T=time()
for i=1 to 3000 do
ok = find_from_to(100,1000,z,q)
end for
T=time()-T
? T


On my 1.8GHz box I got, for example:

2.41  --  pure find()     -- full range
12.25 --  find_from_to()  -- full range
0.16  --  find_from_to()  -- some suspicious range

Try and try please to be very sure.

Good Luck!

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu