<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: CFSCRIPT List Loop?</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Denstir</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-111</link>
		<dc:creator>Denstir</dc:creator>
		<pubDate>Sat, 17 Dec 2005 04:48:34 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-111</guid>
		<description>Why bother? Thick as a brick comes to mind. Does no one actually _read_ what they are commenting on? Not that I don&#039;t suffer from the same malady, but SHEESH.

Why? Maybe for refactoring? Maybe you are repeating your code, and realize, &quot;hey, I can make a function that does this and save like 100000 lines of code!&quot;? Maybe someone trying to grok the differences between JavaScript and Coldfusion functions and whatnot?

I don&#039;t know and it doesn&#039;t matter. Read the damn blog before you post a damn question. GAAAH!

:-P 

Just ribbin ya, Mr. ecommerce pro. Cuz uh felt like it. Nothing really wrong with questioning and all. :-)

***

Nice little post Barney, some CF noob will no doubt find it useful. I liked the short exp. of the diff. between javascript funcs and cf funcs myself. :-)
</description>
		<content:encoded><![CDATA[<p>Why bother? Thick as a brick comes to mind. Does no one actually _read_ what they are commenting on? Not that I don't suffer from the same malady, but SHEESH.</p>
<p>Why? Maybe for refactoring? Maybe you are repeating your code, and realize, "hey, I can make a function that does this and save like 100000 lines of code!"? Maybe someone trying to grok the differences between JavaScript and Coldfusion functions and whatnot?</p>
<p>I don't know and it doesn't matter. Read the damn blog before you post a damn question. GAAAH!</p>
<p>:-P </p>
<p>Just ribbin ya, Mr. ecommerce pro. Cuz uh felt like it. Nothing really wrong with questioning and all. :-)</p>
<p>***</p>
<p>Nice little post Barney, some CF noob will no doubt find it useful. I liked the short exp. of the diff. between javascript funcs and cf funcs myself. :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert, ecommerce pro</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-110</link>
		<dc:creator>Robert, ecommerce pro</dc:creator>
		<pubDate>Thu, 24 Nov 2005 15:55:06 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-110</guid>
		<description>I also think it&#039;s unnecessary. So why should one bother?</description>
		<content:encoded><![CDATA[<p>I also think it's unnecessary. So why should one bother?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sher</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-109</link>
		<dc:creator>sher</dc:creator>
		<pubDate>Wed, 29 Jun 2005 23:54:43 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-109</guid>
		<description>internet advertising  internet advertising  free advertising  free advertising  advertising specialties  advertising specialties  home depot  home depot  work at home  work at home  home based business  home based business  internet marketing  internet marketing  network marketing  network marketing  search engine marketing  search engine marketing  better business bureau  better business bureau  home based business  home based business  business cards  business cards  shopping cart  shopping cart  ecommerce shopping cart  ecommerce shopping cart  shopping cart software  shopping cart software  house plans  house plans  white house  white house  full house  full house</description>
		<content:encoded><![CDATA[<p>internet advertising  internet advertising  free advertising  free advertising  advertising specialties  advertising specialties  home depot  home depot  work at home  work at home  home based business  home based business  internet marketing  internet marketing  network marketing  network marketing  search engine marketing  search engine marketing  better business bureau  better business bureau  home based business  home based business  business cards  business cards  shopping cart  shopping cart  ecommerce shopping cart  ecommerce shopping cart  shopping cart software  shopping cart software  house plans  house plans  white house  white house  full house  full house</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barney</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-108</link>
		<dc:creator>Barney</dc:creator>
		<pubDate>Wed, 18 May 2005 14:25:13 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-108</guid>
		<description>Yeah, I posted some similar test results in an earlier comment.  With a few elements, the list is faster, but by the time you have even 10 elements, the array takes a fraction of the time.

I&#039;d still recommend a CFLOOP LIST=&quot;&quot; loop if you&#039;re using tags, but if you&#039;re using script (where you don&#039;t have a native list loop), converting to an array is almost always a good idea.</description>
		<content:encoded><![CDATA[<p>Yeah, I posted some similar test results in an earlier comment.  With a few elements, the list is faster, but by the time you have even 10 elements, the array takes a fraction of the time.</p>
<p>I'd still recommend a CFLOOP LIST="" loop if you're using tags, but if you're using script (where you don't have a native list loop), converting to an array is almost always a good idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niklas Richardson</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-107</link>
		<dc:creator>Niklas Richardson</dc:creator>
		<pubDate>Wed, 18 May 2005 08:47:51 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-107</guid>
		<description>Now, these results are very interesting.

Basically, as you said, performing a ListToArray() first and looping over the Array is MUCH quicker than my original suggestion.

My only excuse is that I extrapolated quote from the performance doc to also mean &quot;for&quot; loops (for some reason???).

In any case, I created a test that created a list with 10,000 items with randomly generated data that varied in length between 5 and 15 characters.

I kept the test very simple and merely looped over the list (or array) and set a variable to the item value.

The results are quite staggering.

With a list of 10,000 items these are the results running on CFMX7 on a P4 2Ghz with 1GB Ram:

List Time: ~32,500 ms
Array Time: ~0 ms (max 15 ms)

Perhaps an additional line needs to be added to that coding standards docs about lists in CFSCRIPT!! ;)

I&#039;m posting this code on our blog.

Thanks for the challenge! ;)

Regards

Niklas</description>
		<content:encoded><![CDATA[<p>Now, these results are very interesting.</p>
<p>Basically, as you said, performing a ListToArray() first and looping over the Array is MUCH quicker than my original suggestion.</p>
<p>My only excuse is that I extrapolated quote from the performance doc to also mean "for" loops (for some reason???).</p>
<p>In any case, I created a test that created a list with 10,000 items with randomly generated data that varied in length between 5 and 15 characters.</p>
<p>I kept the test very simple and merely looped over the list (or array) and set a variable to the item value.</p>
<p>The results are quite staggering.</p>
<p>With a list of 10,000 items these are the results running on CFMX7 on a P4 2Ghz with 1GB Ram:</p>
<p>List Time: ~32,500 ms<br />
Array Time: ~0 ms (max 15 ms)</p>
<p>Perhaps an additional line needs to be added to that coding standards docs about lists in CFSCRIPT!! ;)</p>
<p>I'm posting this code on our blog.</p>
<p>Thanks for the challenge! ;)</p>
<p>Regards</p>
<p>Niklas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niklas RIchardson</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-106</link>
		<dc:creator>Niklas RIchardson</dc:creator>
		<pubDate>Wed, 18 May 2005 06:47:33 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-106</guid>
		<description>I see your point.

It would be interesting to compare the performance of a for loop with listToArray() and a for loop with listGetAt() for 100, 1000 items.

Maybe I&#039;ll throw something together if I have some time.

Regards

Niklas</description>
		<content:encoded><![CDATA[<p>I see your point.</p>
<p>It would be interesting to compare the performance of a for loop with listToArray() and a for loop with listGetAt() for 100, 1000 items.</p>
<p>Maybe I'll throw something together if I have some time.</p>
<p>Regards</p>
<p>Niklas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barney</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-105</link>
		<dc:creator>Barney</dc:creator>
		<pubDate>Tue, 17 May 2005 15:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-105</guid>
		<description>Niklas,

Yeah, for what I was doing, a CFLOOP LIST=&quot;&quot; would be perfect, but as the title of the post indicates, I was looking for CFSCRIPT-based version of that loop.  As the MM coding guidelines indicate, listGetAt is inefficient, and so I avoided it by using an array.  Using a CFLOOP tag was impossible, because it can&#039;t be run in CFSCRIPT.</description>
		<content:encoded><![CDATA[<p>Niklas,</p>
<p>Yeah, for what I was doing, a CFLOOP LIST="" would be perfect, but as the title of the post indicates, I was looking for CFSCRIPT-based version of that loop.  As the MM coding guidelines indicate, listGetAt is inefficient, and so I avoided it by using an array.  Using a CFLOOP tag was impossible, because it can't be run in CFSCRIPT.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niklas Richardson</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-104</link>
		<dc:creator>Niklas Richardson</dc:creator>
		<pubDate>Tue, 17 May 2005 14:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-104</guid>
		<description>Oh, it lots some code from the quote above!  It should be:

&quot;Don&#039;t slavishly convert lists to arrays

Even though manipulating an array is generally faster than manipulating a list in CFMX, if you simply need to iterate over a list of items and process each one in turn the faster construct is &lt;cfloop list=&quot;#itemList#&quot; index=&quot;x&quot;&gt; ... &lt;/cfloop&gt;. Don&#039;t convert itemList to an array and then loop over that - it&#039;s not worth it because it probably won&#039;t be faster.&quot;</description>
		<content:encoded><![CDATA[<p>Oh, it lots some code from the quote above!  It should be:</p>
<p>"Don't slavishly convert lists to arrays</p>
<p>Even though manipulating an array is generally faster than manipulating a list in CFMX, if you simply need to iterate over a list of items and process each one in turn the faster construct is &lt;cfloop list="#itemList#" index="x"&gt; &#8230; &lt;/cfloop&gt;. Don't convert itemList to an array and then loop over that &#8211; it's not worth it because it probably won't be faster."</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niklas Richardson</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-103</link>
		<dc:creator>Niklas Richardson</dc:creator>
		<pubDate>Tue, 17 May 2005 14:20:13 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-103</guid>
		<description>Barney,

I understand that looping over an array is quicker than looping through a list.

However, in simple loops (as above), it was my understanding that if you were to convert the list to an array and then loop over the array you would not be increasing performance as some work needs to happen to convert that list to array in the listToArray() function anyway.  So the performance saving is negligable.

This understanding was also confirmed by the ColdFusion MX Coding Guidelines and specifically this bit:

&quot;Don&#039;t slavishly convert lists to arrays

Even though manipulating an array is generally faster than manipulating a list in CFMX, if you simply need to iterate over a list of items and process each one in turn the faster construct is  ... . Don&#039;t convert itemList to an array and then loop over that - it&#039;s not worth it because it probably won&#039;t be faster.&quot;

http://livedocs.macromedia.com/wtg/public/coding_standards/performance.html

Towards the end of the article.

And:

&quot;Use arrays instead of lists - in general

In CFMX, lists suffer from the generally slow string processing in Java which means that list manipulation can be slower than in CF5. In general, it is better to work with arrays of items instead of lists of items: listGetAt() is not an efficient way to work with individual items in a data set! However, see the list vs array caveat in the Don&#039;t section below.&quot;

Regards

Niklas</description>
		<content:encoded><![CDATA[<p>Barney,</p>
<p>I understand that looping over an array is quicker than looping through a list.</p>
<p>However, in simple loops (as above), it was my understanding that if you were to convert the list to an array and then loop over the array you would not be increasing performance as some work needs to happen to convert that list to array in the listToArray() function anyway.  So the performance saving is negligable.</p>
<p>This understanding was also confirmed by the ColdFusion MX Coding Guidelines and specifically this bit:</p>
<p>"Don't slavishly convert lists to arrays</p>
<p>Even though manipulating an array is generally faster than manipulating a list in CFMX, if you simply need to iterate over a list of items and process each one in turn the faster construct is  &#8230; . Don't convert itemList to an array and then loop over that &#8211; it's not worth it because it probably won't be faster."</p>
<p><a href="http://livedocs.macromedia.com/wtg/public/coding_standards/performance.html" rel="nofollow">http://livedocs.macromedia.com/wtg/public/coding_standards/performance.html</a></p>
<p>Towards the end of the article.</p>
<p>And:</p>
<p>"Use arrays instead of lists &#8211; in general</p>
<p>In CFMX, lists suffer from the generally slow string processing in Java which means that list manipulation can be slower than in CF5. In general, it is better to work with arrays of items instead of lists of items: listGetAt() is not an efficient way to work with individual items in a data set! However, see the list vs array caveat in the Don't section below."</p>
<p>Regards</p>
<p>Niklas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Barney</title>
		<link>https://www.barneyb.com/barneyblog/2005/04/12/cfscript-list-loop/comment-page-1/#comment-102</link>
		<dc:creator>Barney</dc:creator>
		<pubDate>Wed, 13 Apr 2005 15:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=86#comment-102</guid>
		<description>Ray: you&#039;re definitely correct.  This is superfluous and unnecessary, since you can do an index loop and dereference the list indexes sequentially.  But that&#039;s not really a list loop.  ; )  Rest assured that I&#039;m not actually using this technique in any of my &#039;real&#039; code, but it&#039;s kind of a neat trick that could be applied to other problems that don&#039;t have readily available alternate solutions.

Niklas: Dereferecing an array is faster than dereferecing a list, particularly when the list is long.  Each list operation has to tokenize the list, while an array is already broken down.  So by doing the tokenization onces (the listToArray call), I save a bunch of time.  I did some quick test, and with just a couple elements, the list operations were quicker.  By the time you had 10 elements, the array method took about 50% of the time, and when you got to 20 elements, the array method took just under 10% of the time.  So for lists that have more than a few elements, converting to an array first will be quicker.</description>
		<content:encoded><![CDATA[<p>Ray: you're definitely correct.  This is superfluous and unnecessary, since you can do an index loop and dereference the list indexes sequentially.  But that's not really a list loop.  ; )  Rest assured that I'm not actually using this technique in any of my 'real' code, but it's kind of a neat trick that could be applied to other problems that don't have readily available alternate solutions.</p>
<p>Niklas: Dereferecing an array is faster than dereferecing a list, particularly when the list is long.  Each list operation has to tokenize the list, while an array is already broken down.  So by doing the tokenization onces (the listToArray call), I save a bunch of time.  I did some quick test, and with just a couple elements, the list operations were quicker.  By the time you had 10 elements, the array method took about 50% of the time, and when you got to 20 elements, the array method took just under 10% of the time.  So for lists that have more than a few elements, converting to an array first will be quicker.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
