Re: Looking for the best "JOIN"
- Posted by Jiri Babor <jbabor at PARADISE.NET.NZ> Oct 22, 2001
- 392 views
Derek, simple concatenation seems to be marginally faster, I got 214,361 : 193,488. Try it. jiri global function joinStrings(sequence s) integer l,a,b sequence t if length(s) = 0 then return s end if l = 0 for i = 1 to length(s) do l += length(s[i]) end for t = repeat(0, l) a = 1 for i = 1 to length(s) do b = a + length(s[i]) - 1 t[a..b] = s[i] a = b + 1 end for return t end function function join(sequence s) sequence r r = {} for i = 1 to length(s) do r &= s[i] end for return r end function -- Test code -- constant words = {"abc","defghi","jklmnopqr","","st","u","vwxyz"} puts(1, join(words) & "\n") puts(1, joinStrings(words) & "\n") atom e sequence k integer x x = 0 e = time() + 10 while e >= time() do x += 1 k =join(words) end while printf(1, "%d interations in 10 seconds\n", x) x = 0 e = time() + 10 while e >= time() do x += 1 k =joinStrings(words) end while printf(1, "%d interations in 10 seconds\n", x)