1. Re: type string

Daniel Berstein <daber at PAIR.COM> wrote

>>Here's Jeff's winning (modified) string type:
>>global type string6(object s)
>>   object c
>>   if not sequence(s) then
>>      return 0
>>   end if
>>   for i = 1 to length(s) do
>>      c = s[i]
>>      if integer(c) then
>>         if (c < 0) or (c > 255) then
>>            return 0
>>         end if
>>      else
>>         return 0
>>      end if
>>   end for
>>   return 1
>>end type
>
>Very fasy!
>
>You should change the not sequence() and integer() test for atom(), if it's
>not a sequence then what is it? and we already know that fp numbers are
>valid characters in Euphoria.
>
>You also need to change c<0 to c<1, zero ain't valid on strings.
>
>global type string(object s)
>        object c
>        if atom(s) then
>                return 0
>        end if
>        for i = 1 to length(s) do
>                c = s[i]
>                if atom(c) then
>                        if (c<1) or (c>255) then
>                                return 0
>                        end if
>                else
>                        return 0
>                end if
>        end for
>        return 1
>end type

Daniel, I ran string6() and your version of string() above thru the
strbench.ex program you posted earlier, and string6() wins every time!

It's because the "not sequence(s)" and "integer(c)" tests are crucial to the
edge that string6() has. Every time I changed one or the other to what you
suggested, the speed dropped. [Using "c<1" instead of "c<0" made no
significant difference.]


Running on a PII 200mHz in DOS under WinNT:
 -------------------------------------------
ex strbench 100000 6

string6z() - 0.001285 "c<0" replaced with "c<1"
string6()  - 0.001288
string6s() - 0.001304 "not sequence(s)" replaced with "atom(s)"
string6i() - 0.001324 "integer(c)" replaced with "atom(c)"
string()   - 0.001344


The far-right digit varied a little, but the other digits remained the same
every time.

Now, I know that Euphoria allows fp values for its string chars, but is it
*really* necessary for the string() type to allow them, too? It's the
biggest speed-killer of the bunch (string6i above).


Be seeing you,
   Gabriel Boehme


 ---------------------
The obligatory quote:

"One of the joys of computers is how they're great at wasting time that
might otherwise be difficult to waste."

Clifford Stoll
 ---------------------

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu