<?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>Thu, 09 Sep 2010 10:53:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: User</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1741</link>
		<dc:creator>User</dc:creator>
		<pubDate>Wed, 07 Jul 2010 18:49:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1741</guid>
		<description>public IEnumerable Comment()
{
yield return &quot;Good post!!&quot;;
}</description>
		<content:encoded><![CDATA[<p>public IEnumerable Comment()<br />
{<br />
yield return &#8220;Good post!!&#8221;;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# yield keyword &#171; Vincentpoon&#39;s Blog</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1733</link>
		<dc:creator>C# yield keyword &#171; Vincentpoon&#39;s Blog</dc:creator>
		<pubDate>Fri, 21 May 2010 03:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1733</guid>
		<description>[...] http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html" rel="nofollow">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Domain Events &#8211; Don&#8217;t observe us, we&#8217;ll observe you - db@net blog site</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1719</link>
		<dc:creator>Domain Events &#8211; Don&#8217;t observe us, we&#8217;ll observe you - db@net blog site</dc:creator>
		<pubDate>Tue, 13 Apr 2010 08:04:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1719</guid>
		<description>[...] Until now the dominating pattern regarding sequential input was the IEnumarable interface and the &#8220;yield&#8221; keyword in C#. Since the advent of LINQ and the deferred execution mechanism, this Design Pattern has received a [...]</description>
		<content:encoded><![CDATA[<p>[...] Until now the dominating pattern regarding sequential input was the IEnumarable interface and the &#8220;yield&#8221; keyword in C#. Since the advent of LINQ and the deferred execution mechanism, this Design Pattern has received a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dimpu</title>
		<link>http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html/comment-page-1#comment-1716</link>
		<dc:creator>dimpu</dc:creator>
		<pubDate>Wed, 07 Apr 2010 11:29:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2009/02/using-c-yield-for-readability-and-performance.html#comment-1716</guid>
		<description>yes it is</description>
		<content:encoded><![CDATA[<p>yes it is</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>
