Re: Faster lower() command
- Posted by jacques deschênes <desja at globetrotter.net> Jan 20, 2007
- 554 views
I'm using windows xp pro running on DELL inpiron 1501 with 1Go Ram CPU AMD turion 64x2 1.60Ghz Why euphoria interpreter should create 5 or 6 * 1000000 long sequence? each character is represented by an integer so its a 4000000 bytes array new test
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 t = time() for i = 1 to 1000 do l = lower1(txt) end for ? time() - t t = time() for i = 1 to 1000 do l = lower(txt) end for ? time() - t
result 0.13 0.11 64.2 95.41 This time its clear that lower1() is faster than lower() I don't know how the loop is implemented inside euuphoria interpreter but there is place for optimization! regards, Jacques Deschênes Pete Lomax wrote: > > jacques deschênes wrote: > > on my laptop > > lower1() give .12sec > > lower() give .09sec > I not only agree with other posters but am downright jaw-dropping astonished > that you got lower() to appear faster that lower1() in ANY circumstances! > > My analysis was that lower() must create 5 or 6 * 1,000,000 - long sequences > before finally calculating the result. > > > I can't figure how lower1() can be faster on your machine. > > Are you by any chance on a Linux box while we're all on Windows? > > Puzzled, > Pete