Re: upper()
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Aug 06, 2006
- 679 views
Kat wrote: > > data = repeat({rand(24)+97},1000000) > upperdata = repeat({rand(24)+97},1000000) > > puts(1,"repeats done, press a key\n") > junk = wait_key() > > --for loop = 1 to length(data) do upperdata[loop] = upper(data[loop]) end > for > for loop = 1 to length(data) do upperdata[loop] = data[loop] end for > I found some interesting results. I tried 4 different ways: 1:}}} <eucode> upperdata = upper(data) </eucode> {{{ 2:}}} <eucode> for loop = 1 to length(data) do upperdata[loop] = upper(data[loop]) end for 3:}}} <eucode> upperdata = c_func( c_upper, { data } )</eucode> {{{ (compiled wildcard.e into a dll) 4:}}} <eucode> object x constant TO_LOWER = 'a' = 'A' for loop = 1 to length(data) do x = data[loop] upperdata[loop] = x - (x >= 'a' and x <= 'z') * TO_LOWER end for </eucode> {{{ 5: Compiled this into a dll:
constant TO_LOWER = 'a' - 'A' global function seq_upper(sequence seq) -- convert atom or sequence to upper case sequence y, x y = repeat( 0, length(seq) ) for loop = 1 to length(seq) do x = seq[loop] y[loop] = x - (x >= 'a' and x <= 'z') * TO_LOWER end for return y end function
...and called it by...
upperdata = c_func( c_seq_upper, {data} )
I ran each method under exwc either natively, or using "exwc eu.ex" (ooeu): exwc ooeu 1 4.06 3.85 2 1.10 66.97 3 4.18 4.35 4 1.00 5.83 5 0.97 1.08 (Run on a 2.4GHz Celeron with 512MB RAM.) I really can't explain why ooeu beats exwc on #1. The results of #2 and #4 seem to make it clear that iterating through the sequence (and not forcing more complicated sequence arithmetic) was faster, which took me to #5, which definitely seems to be the best, especially for the ooeu case. And for large datasets, it should more than compensate for the delayed startup time if you don't have the registered translator. Matt Lewis