Re: Faster lower() command
- Posted by Larry Miller <larrymiller at sasktel.net> Jan 20, 2007
- 552 views
jacques deschĂȘnes wrote: > > Hi Jesse, > As I was quite skeptic I made my own test here > }}} <eucode> > 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 > > </eucode> {{{ > 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 > > I can confirm Jesse Adkins findings. On my machine I get the following results: Time for lower1() .06 seconds Time for lower() .24 seconds Reversing lower() and lower1() in the program made little difference. I tried changing the statement "constant tct=repeat('A',1000000)" to "constant tct=repeat('A',10000000)" to get more accurate timings. The time for lower1() was reported as .61 seconds as expected. The time for lower() was taking much longer than expected, then windows reported I was low on virtual memory. It eventually finished after 82 seconds. There was almost continuous disk activity during this time. Possibly not related but it would seem that lower() requires considerably more memory. An incident like this is very rare for me. This is with a 1.3GHZ Pentium4, Windows2000 Professional, 256MB RAM. The lower1() function is very similar to lower_case() found in wild.e by Colin Taylor back in Nov 25 2000. Search for "Faster Wildcard". I have done similar tests in the past, all with similar results. Larry Miller