1. Re: type string
Daniel Berstein <daber at PAIR.COM> wrote:
>>Running on a PII 200mHz in DOS under WinNT:
>> -------------------------------------------
>>exw 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
>>
[snip]
>BTW I avoided some of the randomness of the benchmark under NT using
>exw.exe instead of ex.exe (and the numbers returned are much more "real"
>than those 0.00xxx seconds ex.exe gives).
You're right:
Running EXW in WinNT:
---------------------
exw strbench 400000 6
string8 -- 5.890000 almost identical to string6 [see below]
string6i -- 6.020000 "integer(c)" replaced with "atom(c)"
string -- 6.096667
string6z -- 6.165000 "c<0" replaced with "c<1"
string6 -- 6.173333
string8i -- 6.241667 almost identical to string6i [see below]
string6s -- 6.273333 "not sequence(s)" replaced with "atom(s)"
-- the runner-up
global type string6i(object s)
object c
if not sequence(s) then
return 0
end if
for i = 1 to length(s) do
c = s[i]
if atom(c) then
if (c < 0) or (c > 255) then
return 0
end if
else
return 0
end if
end for
return 1
end type
-- almost the loser
global type string8i(sequence s) -- notice
object c
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
-- the winner!
global type string8z(sequence s) -- ditto
object c
for i = 1 to length(s) do
c = s[i]
if integer(c) then
if (c < 1) or (c > 255) then
return 0
end if
else
return 0
end if
end for
return 1
end type
Apparently, Euphoria can optimize the "integer" test much better when the
incoming object is required to be a sequence. Otherwise, the "atom" test
wins out.
Be seeing you,
Gabriel Boehme
---------------------
The obligatory quote:
Nothing worthwhile is achieved suddenly.
Robert Fripp
---------------------