Is debugging on? All the calls to the functions get tracked in debugging which can add considerable overhead.
It might be more efficient to write these iterators in java and then instantiate the java object in your code. Russ > -----Original Message----- > From: Jonathon Stierman [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 06, 2008 2:02 PM > To: CF-Talk > Subject: iterators > > I've been toying around with the idea of wrapping my output objects in > Iterators on my View pages. The idea is that I'd like my Views to be > relatively independent of the datatype that they're trying to display. So > my View would be able to work with either a Query, Array of Structs, Array > of Beans, all using the same looping code on my .cfm page. So I wrote up > a > definition for my abstract iterator: > > getCurrentPosition():Numeric > getSize():Numeric > reset():Void > skip(numberOfRowsToSkip:Numeric) > skipTo(position:Numeric) > atBeginning():Boolean > hasMore():Boolean > next():Any > previous():Any > current():Any > > And I built a few concrete subclasses of that for each data type: > QueryIterator, ArrayIterator, BeanIterator. And the code for my View > pages > becomes: > > <cfloop from="1" to="#Variables.iterator.getSize()#" index="x"> > <cfset Variables.current = iterator.next() /> > <!--- output the data of the current element (Variables.current) > ---> > </cfloop> > > My problem is that my iterators are running terribly slow. Roughly 10 > times > slower than cfloop'ing for most Queries. I did some basic time trials, > and > here are the averages of the execution times: > > 10 record Query > Iterator: 24 ms > Cfloop: 4 ms > > 100 record Query > Iterator: 24 ms > Cfloop: 4 ms > > 250 record Query > Iterator: 54 ms > Cfloop: 11 ms > > 500 record Query > Iterator: 123 ms > Cfloop: 17 ms > > 1000 record Query > Iterator: 241 ms > Cfloop: 25 ms > > 10000 record Query > Iterator: 2648 ms > Cfloop: 382 ms > > For the smaller record sets, the time difference is negligible, but for > the > larger record sets, the time difference is a little disturbing. I'm not > typically going to be looping over 10000 records all in one page, but it > would let me sleep a little better at night if the time difference is > typical sacrifice for abstracting out a looping mechanism. What has been > your experience with using iterators? Is it worth the abstraction, or > should I just stick to having my Views dependent on the collection type? > > I can post the code for my CFC's and tests as well, if anyone is > interested > in seeing them. > > Jonathon > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:298371 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4