1. Re: type string
Jeff,
The results are interesting. But you forgot to extract loop overhead... =
with that out of the way, string type #2 can still win on longer =
strings.
Also, repacing the three array accesses (s[i]) in string type #3 with a =
single variable 'c' (of type object) increases speed about 40%, or more =
if the string is longer--enough to consistently blow away the others.
(And a final curious discovery... try replacing "hello" and {0,2,-1} =
with constants. Apparently the constants are faster than the literal =
strings... that strikes me as odd.)
Rod Jackson
----------
From: Jeffrey Fielding[SMTP:JJProg at CYBERBURY.NET]
Sent: Thursday, March 11, 1999 7:03 AM
To: EUPHORIA at LISTSERV.MUOHIO.EDU
Subject: Re: type string
I've tested three string routines with this benchmark. I first tested =
without
all the checks to make sure s is a sequence and that it holds all =
integers, and
the string2 won, but then I added the checks and string3 won.
global type string1(object s)
integer i
if not sequence(s) then
return 0
end if
i =3D length(s)
if (i=3D0) or (integer(s[i]) and (s[i]>0) and (s[i]<=3D255) and
string1(s[1..i-1])) then
return 1
end if
return 0
end type
global type string2(object s)
if not sequence(s) then
return 0
end if
for i =3D 1 to length(s) do
if not integer(s[i]) then
return 0
end if
end for
if find(0,(s > 0) and (s <=3D 255)) then
return 0
end if
return 1
end type
global type string3(object s)
if not sequence(s) then
return 0
end if
for i =3D 1 to length(s) do
if not integer(s[i]) then
return 0
end if
if s[i] < 0 or s[i] > 255 then
return 0
end if
end for
return 1
end type
atom t1, t2, t3
integer s
t1 =3D time()
for i =3D 1 to 10000 do
s =3D string1("hello")
if s !=3D 1 then
puts(1,"string1 doesn't work.\n")
exit
end if
s =3D string1({0,2,-1})
if s !=3D 0 then
puts(1,"string1 doesn't work.\n")
exit
end if
end for
t1 =3D time() - t1
t2 =3D time()
for i =3D 1 to 10000 do
s =3D string2("hello")
if s !=3D 1 then
puts(1,"string2 doesn't work.\n")
exit
end if
s =3D string2({0,2,-1})
if s !=3D 0 then
puts(1,"string2 doesn't work.\n")
exit
end if
end for
t2 =3D time() - t2
t3 =3D time()
for i =3D 1 to 10000 do
s =3D string3("hello")
if s !=3D 1 then
puts(1,"string3 doesn't work.\n")
exit
end if
s =3D string3({0,2,-1})
if s !=3D 0 then
puts(1,"string3 doesn't work.\n")
exit
end if
end for
t3 =3D time() - t3
? t1
? t2
? t3
--
Jeffrey Fielding
JJProg at cyberbury.net
http://members.tripod.com/~JJProg/