1. Re: type string
At 09:03 AM 11-03-1999 , you wrote:
>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.
I modified severly your benchmark program and the three algorithms are
fairly close. I'm running on an NT workstations, so to avoid as much as
possible external (multitasking, page swapping, system cache, etc.) noise I
run the test "concurrently".
I'm intrigued of the random nature of results I get. Too much random
results on consecutive runs made me include the multiplier as a way to
further average the results to de-mistify this behaviour. Perhaps my
benchmark code has an error... perhaps not.
By default it performs 1000 iterartions one time with
'1234567890abcdefghijklmnopqrstuvwxyz' as it's test string. The default
iterations, multiplier and test string can be overriden from the command
line: ex bench i m s
Where,
'i' is the number of iterations.
'm' is the multiplier.
's' is the test string.
For example to make 5000 iterations 10 times: ex bench 5000 10
And to use with the above data with the string 'Euphoria is great': ex
bench 5000 10 Euphoria is great
--Code start:
include get.e
sequence str, ids, t, cl
integer iterations, multiplier
object x
global type string1(sequence s)
integer i
i = length(s)
if (i=0) or (integer(s[i]) and (s[i]>0) and (s[i]<=255) 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 = 1 to length(s) do
if not integer(s[i]) then
return 0
end if
end for
if find(0,(s > 0) and (s <= 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 = 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
procedure results(sequence v)
sequence r
integer len, k
len = length(v)
r = repeat({0,0}, len)
for i = len to 1 by -1 do
for j = 1 to length(v) do
if v[j][2] >= r[i][2] then
r[i] = v[j]
k = j
end if
end for
v = v[1..k-1]&v[k+1..length(v)]
end for
for i = 1 to len do
printf(1, "\tstring%d: %f\n", {r[i][1], r[i][2]})
end for
end procedure
function test(atom id)
integer i
atom t
t = time()
i = call_func(id, {str})
return time()-t
end function
iterations = 1000
multiplier = 1
str = "1234567890abcdefghijklmnopqrstuvwxyz"
cl = command_line()
if length(cl) > 2 then
x = value(cl[3])
if x[1] = GET_SUCCESS and integer(x[2]) then
iterations = x[2]
end if
if length(cl) > 3 then
x = value(cl[4])
if x[1] = GET_SUCCESS and integer(x[2]) then
multiplier = x[2]
end if
end if
if length(cl) > 4 then
str = cl[5]
for i = 6 to length(cl) do
str = str & " " & cl[i]
end for
end if
end if
ids = {}
ids = append(ids, routine_id("string1"))
ids = append(ids, routine_id("string2"))
ids = append(ids, routine_id("string3"))
t = {0,0,0}
printf(1, "Performing %d iterations %d times.\nTest string: %s\nPlease
wait...\n\n", {iterations, multiplier, str})
for j = 1 to multiplier do
for i = 1 to iterations do
t[1] += test(ids[1])
t[2] += test(ids[2])
t[3] += test(ids[3])
end for
end for
Regards,
Daniel Berstein
[daber at pair.com]