Re: all() and any() routines
- Posted by Arthur Adamson <euclid at HORANDATA.NET> Mar 22, 1997
- 1221 views
--=====================_859055508==_ >Poster: Ad Rienks <Ad_Rienks at COMPUSERVE.COM> >Subject: all() and any() routines >------------------------------------------------------------------------------- > >Jef Zeitlin provided us with some very nice routines, all() and any(). >But when I began testing it with 200000 and 300000 elements, the speed >difference decreased, I think maybe because most of the time was spend >writing to and reading from the hard disk. >Can someone with more RAM test this? I ran some tests. The results follow. My conclusion, it all depends. If someone can direct me to a fine grained timer, I will re-run. The 200000 results suffer from coarse timer resolution. Art Adamson ------------------------------------------------------------------------------ --=====================_859055508==_ The following data shows relative speed for Mr Zeitlin's loop based any and all functions vs Mr. Rienk's find based any and all which was offered as hopefully faster. My answer, they are about the same with some exceptions....asssuming I have implemented them properly. My versions follow in the include file I used. The 200000 versions results suffer from lack of timer resolution. Is there a better timer available for Euphoria, I can easily retest. Art Adamson, euclid at horandata.net INCLUDE FILE: --2 versions of any and all for speed comparison tests --Art Adamson, euclid at horandata.net --loop version by Zeitlin global function allloop(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 --allloop() global function anyloop(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 --anyloop() --find version by Rienks global function all(object o) if atom(o) then return o end if if find(0,o) then return 0 else return 1 end if end function --all() global function any(object o) if atom(o) then return o end if if find(1,o) then return 1 else return 0 end if end function --any() END INCLUDE FILE ||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||||||||||||| Test of loop vs find anyall.e for FLOATS and sequence length :200000 Time for all/any with-find...with-loop are shown thus, 0.66...0.65 Using a pentium, 100/120 MHZ, 30 Meg Ram... **Test of All******************************************** The sequence is filled with 3.22345.....,,,,,,,.......find...loop Using all(s < 2.22345), the answer is: No, time is: 0.11 Repeat above test to test cache effects Using all(s < 2.22345), the answer is: No, time is: 0.16...0.11 Using all(s > 2.22345), the answer is: Yes, time is: 0.17...0.22 Using all(s > 4.22345), the answer is: No, time is: 0.11...0.11 Using all(s >=4.22345), the answer is: No, time is: 0.16...0.11 Using all(s <= 4.22345), the answer is: Yes, time is: 0.17...0.16 **Test of Any******************************************** Using any(s > 4.22345), the answer is: No, time is: 0.17...0.22 Using any(s < 4.22345), the answer is: Yes, time is: 0.11...0.16 Using any(s < 2.22345), the answer is: No, time is: 0.11...0.22 Using any(s = 4.22345), the answer is: No, time is: 0.11...0.16 Using any(s >= 4.22345), the answer is: No, time is: 0.17...0.16 Using any(s <= 4.22345), the answer is: Yes, time is: 0.16..,0.11 ||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||||||||||||| Test of loop vs find anyall.e for FLOATS and sequence length :2000000 Time for all/any with-find...with-loop are shown thus, 0.66...0.65 Using a pentium, 100/120 MHZ, 30 Meg Ram... **Test of All******************************************** The sequence is filled with 3.22345.....,,,,,,,.......find...loop Using all(s < 2.22345), the answer is: No, time is: 1.37 Repeat above test to test cache effects Using all(s < 2.22345), the answer is: No, time is: 1.32...1.26 Using all(s > 2.22345), the answer is: Yes, time is: 1.48...1.98 Using all(s > 4.22345), the answer is: No, time is: 1.32...1.32 Using all(s >=4.22345), the answer is: No, time is: 1.26...1.32 Using all(s <= 4.22345), the answer is: Yes, time is: 1.43...1.98 **Test of Any******************************************** Using any(s > 4.22345), the answer is: No, time is: 1.43...2.03 Using any(s < 4.22345), the answer is: Yes, time is: 1.26...1.32 Using any(s < 2.22345), the answer is: No, time is: 1.43...2.03 Using any(s = 4.22345), the answer is: No, time is: 1.43...1.98 Using any(s >= 4.22345), the answer is: No, time is: 1.48...1.98 Using any(s <= 4.22345), the answer is: Yes, time is: 1.26..,1.32 ||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||||||||||||||||||||||||| Test of loop vs find anyall.e for FLOATS and sequence length :4000000 Time for all/any with-find...with-loop are shown thus, 0.66...0.65 Using a pentium, 100/120 MHZ, 30 Meg Ram... **Test of All******************************************** The sequence is filled with 3.22345.....,,,,,,,.......find...loop Using all(s < 2.22345), the answer is: No, time is: 3.41 Repeat above test to test cache effects Using all(s < 2.22345), the answer is: No, time is: 2.58...2.58 Using all(s > 2.22345), the answer is: Yes, time is: 2.91...4.01 Using all(s > 4.22345), the answer is: No, time is: 2.64...2.58 Using all(s >=4.22345), the answer is: No, time is: 2.58...2.64 Using all(s <= 4.22345), the answer is: Yes, time is: 2.91...3.96 **Test of Any******************************************** Using any(s > 4.22345), the answer is: No, time is: 2.91...4.01 Using any(s < 4.22345), the answer is: Yes, time is: 2.58...2.58 Using any(s < 2.22345), the answer is: No, time is: 2.91...4.12 Using any(s = 4.22345), the answer is: No, time is: 2.91...3.96 Using any(s >= 4.22345), the answer is: No, time is: 2.91...3.95 Using any(s <= 4.22345), the answer is: Yes, time is: 2.58..,2.64 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII Test of loop vs find anyall.e for INTEGERS and sequence length :200000 Time for all/any with-find...with-loop are shown thus, 0.66...0.65 Using a pentium, 100/120 MHZ, 30 Meg Ram... **Test of All******************************************** The sequence is filled with 3 .....,,,,,,,.......find...loop Using all(s < 2 ), the answer is: No, time is: 0.06 Repeat above test to test cache effects Using all(s < 2 ), the answer is: No, time is: 0.05...0.06 Using all(s > 2 ), the answer is: Yes, time is: 0.05...0.16 Using all(s > 4 ), the answer is: No, time is: 0.06...0.05 Using all(s >=4 ), the answer is: No, time is: 0.06...0.05 Using all(s <= 4 ), the answer is: Yes, time is: 0.06...0.16 **Test of Any******************************************** Using any(s > 4 ), the answer is: No, time is: 0.06...0.11 Using any(s < 4 ), the answer is: Yes, time is: 0.05...0.06 Using any(s < 2 ), the answer is: No, time is: 0.11...0.11 Using any(s = 4 ), the answer is: No, time is: 0.05...0.17 Using any(s >= 4 ), the answer is: No, time is: 0.05...0.11 Using any(s <= 4 ), the answer is: Yes, time is: 0.06..,0.05 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII Test of loop vs find anyall.e for INTEGERS and sequence length :2000000 Time for all/any with-find...with-loop are shown thus, 0.66...0.65 Using a pentium, 100/120 MHZ, 30 Meg Ram... **Test of All******************************************** The sequence is filled with 3 .....,,,,,,,.......find...loop Using all(s < 2 ), the answer is: No, time is: 0.66 Repeat above test to test cache effects Using all(s < 2 ), the answer is: No, time is: 0.55...0.55 Using all(s > 2 ), the answer is: Yes, time is: 0.71...1.27 Using all(s > 4 ), the answer is: No, time is: 0.6...0.55 Using all(s >=4 ), the answer is: No, time is: 0.55...0.55 Using all(s <= 4 ), the answer is: Yes, time is: 0.71...1.27 **Test of Any******************************************** Using any(s > 4 ), the answer is: No, time is: 0.71...1.26 Using any(s < 4 ), the answer is: Yes, time is: 0.55...0.55 Using any(s < 2 ), the answer is: No, time is: 0.72...1.26 Using any(s = 4 ), the answer is: No, time is: 0.71...1.27 Using any(s >= 4 ), the answer is: No, time is: 0.71...1.26 Using any(s <= 4 ), the answer is: Yes, time is: 0.55..,0.55 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII Test of loop vs find anyall.e for INTEGERS and sequence length :4000000 Time for all/any with-find...with-loop are shown thus, 0.66...0.65 Using a pentium, 100/120 MHZ, 30 Meg Ram... **Test of All******************************************** The sequence is filled with 3 .....,,,,,,,.......find...loop Using all(s < 2 ), the answer is: No, time is: 1.76 Repeat above test to test cache effects Using all(s < 2 ), the answer is: No, time is: 1.16...1.1 Using all(s > 2 ), the answer is: Yes, time is: 1.42...2.53 Using all(s > 4 ), the answer is: No, time is: 1.15...1.1 Using all(s >=4 ), the answer is: No, time is: 1.16...1.1 Using all(s <= 4 ), the answer is: Yes, time is: 1.42...2.53 **Test of Any******************************************** Using any(s > 4 ), the answer is: No, time is: 1.43...2.47 Using any(s < 4 ), the answer is: Yes, time is: 1.15...1.1 Using any(s < 2 ), the answer is: No, time is: 1.43...2.53 Using any(s = 4 ), the answer is: No, time is: 1.48...2.48 Using any(s >= 4 ), the answer is: No, time is: 1.42...2.48 Using any(s <= 4 ), the answer is: Yes, time is: 1.15..,1.1 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII --=====================_859055508==_ Arthur P. Adamson, The Engine Man, euclid at mail.horandata.net --=====================_859055508==_--