Re: Faster please....

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

You are absolutly correct Pete, I should have tested the routines
thoroughly.

Here are two version (that run fine) Im hopeing for a challenger
that will provide a faster routine or tweak the existing code (below)

Have fun!

global function sDelimited1(sequence s1, sequence s2)
integer len, start, endx
sequence dseq,dl --  didn't define dl
dseq=3D{}          --  didn't initialize this

   len =3D length(s2)
   start =3D 1
   for i =3D 1 to len do
       if equal(s2[i..i],s1) then
          endx =3D i - 1
          dseq &=3D {s2[start..endx]}
          start =3D i + 1
       end if
   end for
   return dseq
end function


function sNest(sequence s1, sequence s2)
  integer start, endx
  sequence dseq

  dseq =3D {}
  start =3D 1
  for i =3D 1 to length(s1) do
      endx =3D s1[i]
      dseq &=3D {s2[start..endx-1]}
      start =3D endx + 1
  end for
  return dseq
end function

function sDelimited( sequence s1, sequence s2 )
  object found

  found =3D match( s1, s2 )
  if found then
    found &=3D found + sDelimited( s1, s2[found+1..length(s2)] )
  else
    return {}
  end if
  return found
end function

----------- test function ---------
sequence dl, test
object data
integer stop
atom t

dl=3Drepeat(127,1)

t =3D time()
for i =3D 1 to 10000 do
test =3D "Euman"&dl&"Euphoria"&dl&"Programmer"&dl&"this is a test"&dl

--uncomment to run the other method (which is only a few hundredths of a se=
c
--                                                        faster than the
first routine...)
--data=3DsNest(sDelimited("=7F", test), test)

-- make sure you comment out the next line when running the above routine!
data=3DsDelimited1("=7F", test)
end for
t =3D time() - t
puts(1, sprintf("%2.3f", t)&'\n')

for i=3D1 to 4 do
puts(1, data[i]&'\n')
end for
stop=3Dgetc(0)

Euman

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

Search



Quick Links

User menu

Not signed in.

Misc Menu