Re: type string
- Posted by ddhinc <ddhinc at ALA.NET> Mar 17, 1999
- 461 views
Rod Jackson wrote: >Christopher, are you using Daniel's benchmark program? I haven't used that yet, >I think it might help if I started though... No, I made my own benchmark because Daniel's benchmark includes alot of code which relies on version 2.1 (short-circuiting etc.). I'm still using 2.0 at the moment. This could also account for some benchmarking differences in comparing string12() to string13() due to some other optimizations made in 2.1 itself. Anyway, here's the method I used to compare the two type functions: ---------------------------------------------------------------- constant iter = 10000 constant pre_fill = 10 include machine.e tick_rate(1000) -- with profile_time -- with trace trace(1) ---------------------------------------------------------------- global type string12(object x) sequence s if not sequence(x) then return 0 end if s = x -- this is key for i = 1 to length(s) do x = s[i] if integer(x) then if x < 1 then return 0 elsif x > 255 then return 0 end if else return 0 end if end for return 1 end type ---------------------------------------------------------------- global type string13(object x) if atom(x) then return 0 end if -- ensure all elements are in range 0 to 255 if compare(x, and_bits(255, x)) then return 0 end if -- ensure there's no sub-sequences for i = 1 to length(x) do if not integer(x[i]) then return 0 end if end for return 1 end type ---------------------------------------------------------------- sequence test_set sequence base_str integer trash atom t base_str = {} for x = 1 to pre_fill do base_str = base_str & "1234567890abcdefghijklmnopqrstuvwxyz" end for test_set = { base_str & "1234567890abcdefghijklmnopqrstuvwxyz", base_str & "abcdefghijklm" & 37.54 & "nopqrstuvwxyz", base_str & "abcdefghijklm" & -54 & "nopqrstuvwxyz", base_str & "abcdefghijklm" & 540 & "nopqrstuvwxyz", base_str & "abcdefghijklm" & { "nopqrstuvwxyz" } } printf(1, "String12: ", {}) t = time() for x = 1 to iter do for y = 1 to length(test_set) do trash = string12(test_set[y]) end for end for ? time() - t printf(1, "String13: ", {}) t = time() for x = 1 to iter do for y = 1 to length(test_set) do trash = string13(test_set[y]) end for end for ? time() - t ---------------------------------------------------------------- Giving results like this on my P90: C:\EUPHORIA>ex string2 String12: 21.2838 String13: 13.9119 I'd be interested in knowing if this yields quite different results under version 2.1 vs. 2.0. Thanks, Christopher D. Hickman