Re: Faster lower() command
- Posted by jacques deschênes <desja at globetrotter.net> Jan 20, 2007
- 551 views
Hi Jesse, As I was quite skeptic I made my own test here
function lower1( sequence x ) integer c for i = 1 to length(x) do c = x[i] if c <= 'Z' then if c >= 'A' then x[i] = c + 32 end if end if end for return x end function function lower(object o) return o + (o>='A' and o<='Z')*32 -- work as well with atom or sequence end function atom t constant txt=repeat('A',1000000) sequence l t = time() l = lower1(txt) ? time()-t t = time() l = lower(txt) ? time()-t
on my laptop lower1() give .12sec lower() give .09sec As I expected the for loop is slower than the interpreter internal loop. I can't figure how lower1() can be faster on your machine. regards, Jacques Deschênes Jesse Adkins wrote: > > jacques deschênes wrote: > > > > here is the power of euphoria > > > > }}} <eucode> > > function lower(object o) > > return o + (o>='A' and o<='Z')*32 -- work as well with atom or sequence > > end function > > </eucode> {{{ > > > > > > regards, > > Jacques D. > > I'm well aware of that command, since it's what's in place already. The > command that I put up for display processes a sequence much faster than the > current code for lower(). A test I ran, with all letters in caps, ran about > > twice as fast as the current code. > > I kept the original code for doing atoms, since the guru.ex code doesn't work > so well with atoms for some reason > > I'm hoping the code I posted earlier could become part of Euphoria some day, > > despite the fact that it's a good deal larger than the current lower() > command. > > -- Jesse Adkins.