Re: any and all routines
--=====================_859660234==_
I did some large array timing tests for any and all with the
following results. Art Adamson
--=====================_859660234==_
-- The any and all functions by Zeitlin and Rienks run reliably on my
--Pentium 100 with 32 megs RAM for sequences up to about 4000000 floats.
-- The following program compares the speed of the Zeitlin, anyFor, allFor
--to the Rienks version anyFind and allFind....assuming I executed them
--properly.
-- Both these approaches are limited to about 4,000,000 floats in the array
--for my Pentium 100, 32 Megs Ram, DOS6.22....withput significant disk
--swapping.
-- I created 3 more functions, allLess, allMore, and isIn which do not
--require an "extra" boolean array and which can be adapted to do pretty much
--the same job. My routines are someqhat slower but they work well at up to
--a REMARKABLE limit of 8,000,000+ floats in the array....without
--significant disk swapping.
--Hint, if you try these large arrays, put your swap file in a separate
-- dedicated disk partition. Swap file operation for me with these
-- large sequences has been poor, ie. seemingly endless swapping and
-- lots of use of scandisk to fix up the space after I reboot.
--Surprisingly, changing from floats to integers increases the speed but
--does not increase the 8,000,000 above.
--Speed comparisons are shown in the appended time test file.
--Posted to mailing list by Art Adamson, euclid at horandata.net
--loop version by Zeitlin*********************************************
without type_check
without warning
include file.e
global function allFor(object o)
if atom(o) then return o end if
for i = 1 to length(o) by 1 do
if not o[i] then return 0 end if
end for
return 1
end function --allFor()
global function anyFor(object o)
if atom(o) then return o end if
for i = 1 to length(o) by 1 do
if o[i] then return 1 end if
end for
return 0
end function --anyFor()
--find version by Rienks**********************************************
global function allFind(object o)
if atom(o) then return o end if
if find(0,o) then return 0
else
return 1
end if
end function --allFind()
global function anyFind(object o)
if atom(o) then return o end if
if find(1,o) then return 1
else
return 0
end if
end function --anyFind()
--dumb version by Adamson**************************
function isIn(sequence seqIn, atom a)
for i = 1 to length(seqIn) do
if seqIn[i]=a then return 1 end if
end for
return 0
end function --isIn
function allLess(sequence seqIn, atom a)
for i = 1 to length(seqIn) do
if (seqIn[i] >= a) then return 0 end if
end for
return 1
end function --allLess
function allMore(sequence seqIn, atom a)
for i = 1 to length(seqIn) do
if (seqIn[i] <= a) then return 0 end if
end for
return 1
end function --allMore
--Timing-test program**************************************
--Simple mods of below required for floats instead of integers
global sequence s
object t
integer answer , f
s = repeat(3, 4000000)
f = open("any.out", "a")
puts(f,"\n\n") print(f, length(s))
puts(f, " IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIntegers\n")
puts(f,"** e-time **************first the \"dumb\" version\n")
puts(f,"isIn\t")
t = time()
answer = isIn(s, 2)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
puts(f,"allLess\t")
t = time()
answer = allLess(s, 4)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
puts(f,"allMore\t")
t = time()
answer = allMore(s, 2)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
puts(f,"*********************next the \"for\" version\n")
puts(f,"allFor\t")
t = time()
answer = allFor(s = 3)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
puts(f,"anyFor\t")
t = time()
answer = anyFor(s = 3)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
puts(f,"*********************next the \"find\" version\n")
puts(f,"allFind\t")
t = time()
answer = allFind(s >= 2)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
puts(f,"anyFind\t")
t = time()
answer = anyFind(s >= 2)
t = (time() - t)
printf(f,"%3.3f", t) puts(f,"\n")
close(f)
--end of timing program
--*********************************************************
--Timing tests by Art Adamson for several versions of sequence interrogation.
--euclid at horandata.net March 27, 1997
--4000000 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFloats
--** e-time **************first the "dumb" version
--isIn 3.290
--allLess 3.460
--allMore 3.350
--*********************next the "for" version
--allFor 5.500
--anyFor 2.420
--*********************next the "find" version
--allFind 2.910
--anyFind 2.580
--8000000 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFloats
--** e-time **************first the "dumb" version
--isIn 7.140
--allLess 6.700
--allMore 6.430
--*********************next the "for" version
--!!!!!!!!!!!!!!!!following operations commented out to prevent disk
-- thrashing
--allFor 0.000
--anyFor 0.000
--*********************next the "find" version
--allFind 0.000
--anyFind 0.000
--
--8000000 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIntegers
--** e-time **************first the "dumb" version
--isIn 2.630
--allLess 2.590
--allMore 2.630
--*********************next the "for" version
--!!!!!!!!!!!following commented out to avoid disk thrashing
--allFor 0.000
--anyFor 0.000
--*********************next the "find" version
--allFind 0.000
--anyFind 0.000
--
--4000000 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIntegers
--** e-time **************first the "dumb" version
--isIn 1.320
--allLess 1.320
--allMore 1.320
--*********************next the "for" version
--allFor 4.120
--anyFor 1.160
--*********************next the "find" version
--allFind 1.420
--anyFind 1.100
--
--Conclusions,
--1. Integers much faster
--2. Find-version slightly faster.
--3. Use Dumb version for very large sequences.
--4. Find how to define and use shorter numbers, in sequences
--such as bits, bytes, etc so larger sequences can hopefully
--be used.
--=====================_859660234==_
Arthur P. Adamson, The Engine Man, euclid at mail.horandata.net
--=====================_859660234==_--
|
Not Categorized, Please Help
|
|