RE: Standard Euphoria Library Project

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

Kat wrote:

> 
> What if the passed sequence is "" ?
> 

Hehe oops..

Revised..

function splice(sequence s, integer i)
   if length(s)=0 then return s
   elsif i=1 then return s[2..length(s)]
   elsif i=length(s) then return s[1..i-1]
   else return s[1..i-1] & s[i+1..length(s)]
end function


> I think Robert said getting the length of the seq is as fast as getting 
> the first element of 
> the seq. The seq attribute data is stored, such as the length is stored 
> in a basic string 
> as the [0] byte.
> 
Actually I just did a little speed test...

In the case of my function here..
The speed is identical..

IMHO, length() is faster because predefining it requires extra calls..

I tried a different test too.. and it worked out to be just slightly 
faster..

I made a two for loops with 100,000,000 iterations, one used length(), 
the other used the predefined variable.. (defined outside the loop).. I 
made 5 calls to the sequence length in each for loop..

The prior was faster on every attempt by about 1mS.. averaging 36mS for 
the ENTIRE loop, where the latter averaged 37mS on my comp..

I think this is because EUdoesn't have to look as far into the look up 
table for length() as it does for the variable..


Chris {:o)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu