<?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: Using C# Yield for Readability and Performance</title>
	<atom:link href="http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html</link>
	<description>Productive software development using ASP.NET, C#, Adobe Flex, and other technologies and tools.</description>
	<lastBuildDate>Sun, 14 Mar 2010 12:04:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: yield的使用及原理 &#171; 宅爸爸的天空</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1682</link>
		<dc:creator>yield的使用及原理 &#171; 宅爸爸的天空</dc:creator>
		<pubDate>Sat, 16 Jan 2010 08:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1682</guid>
		<description>[...]  [...]</description>
		<content:encoded><![CDATA[<p>[...]  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nariman</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1605</link>
		<dc:creator>Nariman</dc:creator>
		<pubDate>Wed, 30 Sep 2009 14:12:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1605</guid>
		<description>There are definite performance gains to be had - here&#039;s a good sample:
http://flimflan.com/blog/ThePowerOfYieldReturn.aspx</description>
		<content:encoded><![CDATA[<p>There are definite performance gains to be had &#8211; here&#8217;s a good sample:<br />
<a href="http://flimflan.com/blog/ThePowerOfYieldReturn.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/flimflan.com/blog/ThePowerOfYieldReturn.aspx?referer=');">http://flimflan.com/blog/ThePowerOfYieldReturn.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Understanding LINQ and LINQ to SQL (and EF)</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1589</link>
		<dc:creator>Understanding LINQ and LINQ to SQL (and EF)</dc:creator>
		<pubDate>Thu, 17 Sep 2009 15:18:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1589</guid>
		<description>[...] For a moment, forget that LINQ exists. Let’s say that you wanted to filter a list of names, to only get names that start with the letter “J”. You could write the following “utility” function: (if you don’t understand “yield return”, see this post on that topic). [...]</description>
		<content:encoded><![CDATA[<p>[...] For a moment, forget that LINQ exists. Let’s say that you wanted to filter a list of names, to only get names that start with the letter “J”. You could write the following “utility” function: (if you don’t understand “yield return”, see this post on that topic). [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1585</link>
		<dc:creator>Ed</dc:creator>
		<pubDate>Sun, 13 Sep 2009 03:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1585</guid>
		<description>Why not just have a count property and a getItem(int index) method. Perfect clarity, less overhead and no surprises (also totality thread safe).</description>
		<content:encoded><![CDATA[<p>Why not just have a count property and a getItem(int index) method. Perfect clarity, less overhead and no surprises (also totality thread safe).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1511</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 26 Jun 2009 04:09:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1511</guid>
		<description>I hate these web-based interfaces.  That was supposed to be the typed version, IEnumerable&amp;ltT&gt;, not IEnumerable which is much slower.</description>
		<content:encoded><![CDATA[<p>I hate these web-based interfaces.  That was supposed to be the typed version, IEnumerable&amp;ltT&gt;, not IEnumerable which is much slower.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1510</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 26 Jun 2009 04:06:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1510</guid>
		<description>I haven&#039;t checked memory usage, but yield appears to be awesome speed-wise, at least in this simple little test I ran.

Say I want to return a list of 20 items to process.  The fastest way to allocate such a list should be a single allocation of a fixed size array, but it turns out that allocation, copying, and processing takes about 20% longer than creating an IEnumerable to directly iterate through the items.  The advantage of the second case of course is there&#039;s no need to copy the elements.  You just allocate and access.


// elapsed: 00:00:03.4531250
static IEnumerable GetNumbers()
{
    for(int i = 0; i &lt; 20; i++)
    {
        yield return i;
    }
}

// elapsed: 00:00:04.2500000
static IEnumerable GetNumbersArray()
{
    int[] retval = new int[20];

    for(int i = 0; i &lt; 20; i++)
    {
        retval[i] = i;
    }

    return retval;
}

static void Main(string[] args)
{
    int sum = 0;
    DateTime begin = DateTime.Now;
    for(int i = 0; i &lt; (1 &lt;&lt; 24); i++)
    {
        foreach(int j in
/*
            GetNumbers()
*/
            GetNumbersArray()
        )
        {
            sum += j;
        }
    }
    DateTime end = DateTime.Now;
    Console.WriteLine(
        &quot;elapsed: &quot; +
        (end - begin).ToString()
    );
    Console.WriteLine(sum);
}</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t checked memory usage, but yield appears to be awesome speed-wise, at least in this simple little test I ran.</p>
<p>Say I want to return a list of 20 items to process.  The fastest way to allocate such a list should be a single allocation of a fixed size array, but it turns out that allocation, copying, and processing takes about 20% longer than creating an IEnumerable to directly iterate through the items.  The advantage of the second case of course is there&#8217;s no need to copy the elements.  You just allocate and access.</p>
<p>// elapsed: 00:00:03.4531250<br />
static IEnumerable GetNumbers()<br />
{<br />
    for(int i = 0; i &lt; 20; i++)<br />
    {<br />
        yield return i;<br />
    }<br />
}</p>
<p>// elapsed: 00:00:04.2500000<br />
static IEnumerable GetNumbersArray()<br />
{<br />
    int[] retval = new int[20];</p>
<p>    for(int i = 0; i &lt; 20; i++)<br />
    {<br />
        retval[i] = i;<br />
    }</p>
<p>    return retval;<br />
}</p>
<p>static void Main(string[] args)<br />
{<br />
    int sum = 0;<br />
    DateTime begin = DateTime.Now;<br />
    for(int i = 0; i &lt; (1 &lt;&lt; 24); i++)<br />
    {<br />
        foreach(int j in<br />
/*<br />
            GetNumbers()<br />
*/<br />
            GetNumbersArray()<br />
        )<br />
        {<br />
            sum += j;<br />
        }<br />
    }<br />
    DateTime end = DateTime.Now;<br />
    Console.WriteLine(<br />
        &#8220;elapsed: &#8221; +<br />
        (end &#8211; begin).ToString()<br />
    );<br />
    Console.WriteLine(sum);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Schneider</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1498</link>
		<dc:creator>Jon Schneider</dc:creator>
		<pubDate>Mon, 22 Jun 2009 17:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1498</guid>
		<description>This was helpful, thanks!</description>
		<content:encoded><![CDATA[<p>This was helpful, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# Yield Keyword &#171; Vasu Balakrishnan&#8217;s Blog</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1455</link>
		<dc:creator>C# Yield Keyword &#171; Vasu Balakrishnan&#8217;s Blog</dc:creator>
		<pubDate>Wed, 20 May 2009 19:36:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1455</guid>
		<description>[...] Using C# Yield for Readability and Performance [...]</description>
		<content:encoded><![CDATA[<p>[...] Using C# Yield for Readability and Performance [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: t4</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1445</link>
		<dc:creator>t4</dc:creator>
		<pubDate>Thu, 14 May 2009 21:40:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1445</guid>
		<description>I found the same article as Tuan (along with your own article, which looks to be the true source), and the article mentioned by Tuan still seems to be active. The author (patel.dhiren.i@gmail.com) doesn&#039;t seem to have any reservations about copying your article for his own uses...</description>
		<content:encoded><![CDATA[<p>I found the same article as Tuan (along with your own article, which looks to be the true source), and the article mentioned by Tuan still seems to be active. The author (patel.dhiren.i@gmail.com) doesn&#8217;t seem to have any reservations about copying your article for his own uses&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1421</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 27 Apr 2009 14:23:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1421</guid>
		<description>Tuan, I have contacted that site to have that removed. This post was copied without my permission.

Thank you for reporting that.</description>
		<content:encoded><![CDATA[<p>Tuan, I have contacted that site to have that removed. This post was copied without my permission.</p>
<p>Thank you for reporting that.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
