<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Roger Alsing Weblog &#187; .NET</title>
	<atom:link href="http://rogeralsing.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://rogeralsing.com</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 08:00:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='rogeralsing.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Roger Alsing Weblog &#187; .NET</title>
		<link>http://rogeralsing.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://rogeralsing.com/osd.xml" title="Roger Alsing Weblog" />
	<atom:link rel='hub' href='http://rogeralsing.com/?pushpress=hub'/>
		<item>
		<title>Fake Fibers using Async CTP</title>
		<link>http://rogeralsing.com/2011/04/15/fake-fibers-using-async-ctp/</link>
		<comments>http://rogeralsing.com/2011/04/15/fake-fibers-using-async-ctp/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 10:39:52 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 5 Async]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=1004</guid>
		<description><![CDATA[This is another PoC, building recursive code with continuations using the Async CTP. The code creates a fake fiber, which can be suspended and resumed, thus allowing us to &#8220;step&#8221; through its actions. This technique could be useful when building an interpreting language where you might want to step through the expressions.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=1004&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is another PoC, building recursive code with continuations using the Async CTP.</p>
<p>The code creates a fake fiber, which can be suspended and resumed, thus allowing us to &#8220;step&#8221; through its actions.<br />
This technique could be useful when building an interpreting language where you might want to step through the expressions.</p>
<p><pre class="brush: csharp;">
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.CompilerServices;


namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            FakeFiber f = new MyFiber();

            f.Run();
            while (true)
            {
                //tell fiber to continue
                f.Continue();
                Console.ReadLine();
            }
        }
    }

    public class MyFiber : FakeFiber
    {

        //recursive loop that never throws stack overflow
        async void DoLoop(int count)
        {
            await Yield(); //clear callstack

            Console.WriteLine(&quot;{0} {1}&quot;, count, System.Threading.Thread.CurrentThread.ManagedThreadId); 
            
            //we can fetch values from other functions too
            //w/o blowing the call stack
            var i = await IntFunc();
            
            Console.WriteLine(&quot;got func result {0}&quot;,i);
                     
            if (count == 0)
                return;

            DoLoop(count - 1);
        }

        private async Task&lt;int&gt; IntFunc()
        {
            await Yield(); //clear callstack
            return 1;
        }

        public override void Run()
        {
            DoLoop(100000);
        }
    }

    public abstract class FakeFiber
    {
        public abstract void Run();
        private Task currentTask;
        public bool IsCompleted = false;
        public void Continue()
        {
            var task = currentTask;
            if (task != null)
            {
                task.Start();
                task.Wait();
            }
        }

        protected Task Yield()
        {
            currentTask = new Task(() =&gt; { this.currentTask = null; });
            return currentTask;
        }
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/1004/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/1004/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/1004/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=1004&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/04/15/fake-fibers-using-async-ctp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>F# style Mailbox / Agent using C# async CTP</title>
		<link>http://rogeralsing.com/2011/04/15/f-style-mailbox-agent-using-c-async-ctp/</link>
		<comments>http://rogeralsing.com/2011/04/15/f-style-mailbox-agent-using-c-async-ctp/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 08:33:54 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=997</guid>
		<description><![CDATA[More info on TPL DataFlow can be found here : http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d5b3e1f8-c672-48e8-baf8-94f05b431f5c Here is a (naive) F# style Mailbox / Agent using the C# async CTP : This way, we can spawn thousands of agents w/o allocating threads for each of them. The message loop is executed on the threadpool for each iteration and then suspended [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=997&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>More info on TPL DataFlow can be found here : <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d5b3e1f8-c672-48e8-baf8-94f05b431f5c">http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d5b3e1f8-c672-48e8-baf8-94f05b431f5c</a></p>
<p>Here is a (naive) F# style Mailbox / Agent using the C# async CTP :</p>
<p><pre class="brush: csharp;">
    class Program
    {
        static void Main(string[] args)
        {
            var agents = new List&lt;MyAgent&gt;();
            //create 100 000 agents
            for (int i = 0; i &lt; 100000; i++)
                agents.Add(new MyAgent());

            //buffer some messages
            agents.AsParallel().ForAll(a =&gt; a.Send(DateTime.Now.ToString()));

            //start agents
            agents.AsParallel().ForAll(a =&gt; a.Run());

            //send some more messages
            agents.AsParallel().ForAll(a =&gt; a.Send(DateTime.Now.ToString()));

            Console.ReadLine();
        }
    }

    public class MyAgent : Mailbox&lt;string&gt;
    {
        
        public override async void Run()
        {
            while (true)
            {
                var message = await Receive();                
                Console.WriteLine(&quot;Agent {0} got {1}&quot;,this.Id, message);
            }
        }
    }

    public abstract class Mailbox&lt;T&gt;
    {
        private static int id;

        protected Mailbox()
        {
            this.Id = id++;
        }

        public int Id { get;protected set; }

        BufferBlock&lt;T&gt; buffer = new BufferBlock&lt;T&gt;();

        
        public abstract void Run();
        
        
        public void Send(T message)
        {
            buffer.SendAsync(message);
        }

        protected async Task&lt;T&gt; Receive()
        {
            return await buffer.ReceiveAsync();
        }
    }
</pre></p>
<p>This way, we can spawn thousands of agents w/o allocating threads for each of them.<br />
The message loop is executed on the threadpool for each iteration and then suspended untill a new message arrives.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/997/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/997/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/997/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/997/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/997/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/997/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/997/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=997&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/04/15/f-style-mailbox-agent-using-c-async-ctp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>Async CTP first impressions</title>
		<link>http://rogeralsing.com/2011/04/14/async-ctp-first-impressions/</link>
		<comments>http://rogeralsing.com/2011/04/14/async-ctp-first-impressions/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 08:07:29 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=989</guid>
		<description><![CDATA[This is just my first observations. nothing fancy.. I&#8217;ve just installed the new Async CTP (for C# 5 async features) The SP1 Refresh can be found here: http://msdn.microsoft.com/sv-se/vstudio/async/ The new async and await features makes async programming so much sweeter, it lets you write async code in a sequential manner. e.g. This code looks sequential, but the code will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=989&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is just my first observations. nothing fancy..</p>
<p>I&#8217;ve just installed the new Async CTP (for C# 5 async features)<br />
The SP1 Refresh can be found here: <a href="http://msdn.microsoft.com/sv-se/vstudio/async/">http://msdn.microsoft.com/sv-se/vstudio/async/</a></p>
<p>The new async and await features makes async programming so much sweeter, it lets you write async code in a sequential manner.<br />
e.g.</p>
<p><pre class="brush: csharp;">
static async void ShowGoogleHtmlCode()
{
  WebClient client = new WebClient();
   var result = await client.DownloadStringTaskAsync(&quot;http://www.google.com&quot;);
   Console.WriteLine(result);
}
</pre></p>
<p>This code looks sequential, but the code will return/yield back to the caller when it hits the &#8220;await&#8221; keyword.<br />
Once the expression after &#8220;await&#8221; completes, the code will continue to run.</p>
<p>So far so good.<br />
However, there are some design considerations.</p>
<p>Consider this:</p>
<p><pre class="brush: csharp;">
public async void SetupUi()
{
  var blogService = new BlogServiceClient();
     var categories = await blogService.GetCategories();
  var latestPosts = away blogService.GetLatestPosts();

     this.Categories.DataSource = categories;
     this.Posts.DataSource = latestPosts;
}
</pre></p>
<p>This code will call GetCategories and GetLatestPosts at the same time and then wait for _both_ of them to complete before continuing to fill the GUI elements.<br />
If you are doing a Silverlight app, then you probably want to display each GUI element as soon as possible, and thus, the above code could be rewritten to:</p>
<p><pre class="brush: csharp;">
public async void SetupUi()
{
  SetupCategories();
  SetupPosts();
}

public async void SetupCategories()
{
  var blogService = new BlogServiceClient();
     var categories = await blogService.GetCategories();
     this.Categories.DataSource = categories;
}

public async void SetupPosts()
{
  var blogService = new BlogServiceClient();
  var latestPosts = away blogService.GetLatestPosts();
     this.Posts.DataSource = latestPosts;
}
</pre></p>
<p>This way, the async calls will be independent of each other and fill the corresponding GUI element once the data it needs has been fetched.</p>
<p>Also, if you were to write the first code in this way:</p>
<p><pre class="brush: csharp;">
public async void SetupUi()
{
  var blogService = new BlogServiceClient();
     var categories = await blogService.GetCategories();
     this.Categories.DataSource = categories;

  var latestPosts = away blogService.GetLatestPosts();
     this.Posts.DataSource = latestPosts;
}
</pre></p>
<p>In this case, the call to GetCategories would be invoked, and the code waits for it to complete.<br />
Once the categories have been fetched, the GUI element is filled and _then_ the call to GetLatestPost() would be invoked.<br />
Thus, the async calls would not execute at the same time and the time span for the SetupUI to complete would be the same as if all of it were sync code.</p>
<p>Thats all for now..</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/989/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=989&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/04/14/async-ctp-first-impressions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>O/R Mapping and domain query optimizations</title>
		<link>http://rogeralsing.com/2011/04/01/or-mapping-and-domain-query-optimizations/</link>
		<comments>http://rogeralsing.com/2011/04/01/or-mapping-and-domain-query-optimizations/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 08:54:57 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[O/R Mapping]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[EF4]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=977</guid>
		<description><![CDATA[One of the cons of O/R mapping is that the abstraction is a bit too high. You write object-oriented code and often forget about eventual performance problems. Take this (somewhat naive) example: For a given customer, we iterate over all the orders and all the details in those orders and calculate the sum of quantity multiplied [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=977&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the cons of O/R mapping is that the abstraction is a bit too high.<br />
You write object-oriented code and often forget about eventual performance problems.</p>
<p>Take this (somewhat naive) example:</p>
<p><pre class="brush: csharp;">
class Customer
{
   ...
  public double GetOrderTotal()
   {
       var total = ( from order in this.Orders
                        from detail in order.Details
                        select detail.Quantity * detail.ItemPrice)
                       .Sum();

       return total;
   }
}
</pre></p>
<p>For a given customer, we iterate over all the orders and all the details in those orders and calculate the sum of quantity multiplied with itemprice.<br />
So far so good.</p>
<p>This will work fine as long as you have all the data in memory and the dataset is not too large, so chances are that you will not notice any problems with this code in your unit tests.</p>
<p>But what happens if the data resides in the database and we have 1000 orders with 1000 details each?<br />
Now we are in deep s##t, for this code to work, we need to materialize at least 1 (cust) + 1000 (orders) * 1000 (details) entities.<br />
The DB needs to find those 1 000 001 rows , the network needs to push them from the DB server to the App server and the App server needs to materialize all of it.<br />
Even worse, what if you have lazy load enabled and aren&#8217;t loading this data using eager load?<br />
Then you will hit the DB 1 000 001 times&#8230; GL with that! :-)</p>
<p>So clearly, we can not do this in memory, neither with lazy load nor eager load.</p>
<p>But what are the alternatives?<br />
Make an ad hoc sql query?<br />
In that case, what happens to your unit tests?</p>
<p>Maybe we want to keep this code, but we want to execute it in the database instead.</p>
<p>This is possible if we stop beeing anal about &#8220;pure POCO&#8221; or &#8220;no infrastructure in your entities&#8221;</p>
<p>Using an unit of work container such as <a href="https://github.com/rogeralsing/Precio.Infrastructure">https://github.com/rogeralsing/Precio.Infrastructure</a></p>
<p>We can then rewrite the above code slightly:</p>
<p><pre class="brush: csharp;">
class Customer
{
   ...
  public double GetOrderTotal()
   {
  var total = ( from customer in UoW.Query&lt;Customer&gt;() //query the current UoW
                        where customer.Id == this.Id //find the persistent record of &quot;this&quot;
                        from order in customer.Orders
                        from detail in order.Details
                        select detail.Quantity * detail.ItemPrice)
                       .Sum();

       return total;
   }
}
</pre></p>
<p>This code will run the query inside the DB if the current UoW is a persistent UoW.<br />
If we use the same code in our unit tests and use an in mem UoW instance, this code will still work, if our customer is present in the in mem UoW that is..</p>
<p>So the above modification will reduce the number materialized entities from 1 000 001 to 1 (we materialize a double in this case)</p>
<p>I don&#8217;t know about you , but I&#8217;d rather clutter my domain logic slightly and get a million times better performance than stay true to POCO and suffer from a broken app.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/977/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/977/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=977&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/04/01/or-mapping-and-domain-query-optimizations/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>UoW / NWorkspace with Linq support</title>
		<link>http://rogeralsing.com/2011/03/18/uow-nworkspace-with-linq-support/</link>
		<comments>http://rogeralsing.com/2011/03/18/uow-nworkspace-with-linq-support/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 13:08:27 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=974</guid>
		<description><![CDATA[I have blogged about this for quite a while now. Now I&#8217;ve finally cleaned up the code and published it at github:https://github.com/rogeralsing/Precio.Infrastructure This is a small framework for UoW/Workspace support in .NET with Linq support. The framework contains a Unit of Work implementation and providers for Entity Framework 4, NHibernate and MongoDB(using NoRM). There is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=974&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have blogged about this for quite a while now.<br />
Now I&#8217;ve finally cleaned up the code and published it at github:<a href="https://github.com/rogeralsing/Precio.Infrastructure">https://github.com/rogeralsing/Precio.Infrastructure</a></p>
<p>This is a small framework for UoW/Workspace support in .NET with Linq support.</p>
<p>The framework contains a Unit of Work implementation and providers for Entity Framework 4, NHibernate and MongoDB(using NoRM).<br />
There is also a small incomplete Blog sample project included.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/974/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/974/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/974/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/974/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/974/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/974/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/974/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/974/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=974&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/03/18/uow-nworkspace-with-linq-support/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq to SqlXml &#8211; GitHub</title>
		<link>http://rogeralsing.com/2011/03/02/linq-to-sqlxml-github/</link>
		<comments>http://rogeralsing.com/2011/03/02/linq-to-sqlxml-github/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 19:37:50 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[Linq to SqlXml]]></category>
		<category><![CDATA[documentdb]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[ravendb]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Xquery]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=969</guid>
		<description><![CDATA[An early alpha of Linq to SqlXml is now available on github: https://github.com/calyptus/linq-to-sqlxml There is no documentation nor setup scripts so you&#8217;re on your own if you try it. If you get it to run, be sure to add all indexes to the xml field &#8211; primary , secondary &#8211; path , secondary &#8211; value [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=969&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An early alpha of Linq to SqlXml is now available on github: <a href="https://github.com/calyptus/linq-to-sqlxml">https://github.com/calyptus/linq-to-sqlxml</a></p>
<p>There is no documentation nor setup scripts so you&#8217;re on your own if you try it.<br />
If you get it to run, be sure to add all indexes to the xml field &#8211; primary , secondary &#8211; path , secondary &#8211; value , secondary &#8211; property</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/969/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/969/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/969/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=969&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/03/02/linq-to-sqlxml-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq to SqlXML</title>
		<link>http://rogeralsing.com/2011/02/28/linq-to-sqlxml/</link>
		<comments>http://rogeralsing.com/2011/02/28/linq-to-sqlxml/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 12:44:15 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[documentdb]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xpath]]></category>
		<category><![CDATA[Xquery]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=963</guid>
		<description><![CDATA[I&#8217;m hacking along on my Document DB emulator ontop of Sql Server XML columns. I have some decent Linq support in place now. The following query: will yield the following Sql + XQuery to the Sql Server:<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=963&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m hacking along on my Document DB emulator ontop of Sql Server XML columns.</p>
<p>I have some decent Linq support in place now.<br />
The following query:</p>
<p><pre class="brush: csharp;">
var query = from order in orders
            //must have status shipped
            where order.Status &gt;= OrderStatus.Shipped      
            //must contain foo or bar products
            where order.OrderDetails.Any(d =&gt; d.ProductNo == &quot;Foo&quot; || d.ProductNo == &quot;Bar&quot;)
            //must have an order total &gt; 100
            where order.OrderDetails.Sum(d =&gt; d.ItemPrice * d.Quantity) &gt; 100 
            select order;
</pre></p>
<p>will yield the following Sql + XQuery to the Sql Server:</p>
<p><pre class="brush: sql;">
select *
from documents
where CollectionName = 'Order'  and 
--must have an order total &gt; 100
(documentdata.exist('/object/state[(
     fn:sum( 
          for $A in OrderDetails[1]/object/state 
                return ($A/ItemPrice[1] * $A/Quantity[1])) &gt; xs:decimal(100))]') = 1) and 
--must contain foo or bar products
(documentdata.exist('/object/state[OrderDetails[1]/object/state[((ProductNo[1] = &quot;Foo&quot;) or 
 (ProductNo[1] = &quot;Bar&quot;))]]') = 1) and 
--must have status shipped
(documentdata.exist('/object/state[(Status[1] &gt;= xs:int(2))]') = 1)
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/963/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/963/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/963/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=963&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/02/28/linq-to-sqlxml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>Building a Document DB ontop of Sql Server</title>
		<link>http://rogeralsing.com/2011/02/27/building-a-document-db-ontop-of-sql-server/</link>
		<comments>http://rogeralsing.com/2011/02/27/building-a-document-db-ontop-of-sql-server/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 14:12:34 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[documentdb]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[ravendb]]></category>
		<category><![CDATA[xml columns]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=959</guid>
		<description><![CDATA[I&#8217;ve started to build a Document DB emulator ontop of Sql Server XML columns. Sql Server XML columns can store schema free xml documents, pretty much like RavenDB or MongoDB stores schema free Json/Bson documents. XML Columns can be indexed and queried using XPath queries. So I decided to build an abstraction layer ontop of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=959&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started to build a Document DB emulator ontop of Sql Server XML columns.<br />
Sql Server XML columns can store schema free xml documents, pretty much like RavenDB or MongoDB stores schema free Json/Bson documents.</p>
<p>XML Columns can be indexed and queried using XPath queries.</p>
<p>So I decided to build an abstraction layer ontop of this in order to achieve similair ease of use.<br />
I&#8217;ve built a serializer/deserializer that deals with my own XML structure for documents (state + metadata) and also an early Linq provider for querying.</p>
<p>Executing the following code:</p>
<p><pre class="brush: csharp;">
var ctx = new DocumentContext(&quot;main&quot;);
var customers = ctx.GetCollection&lt;Customer&gt;().AsQueryable();

var query = from customer in customers
            where customer.Address.City == &quot;abc&quot; &amp;&amp; customer.Name == &quot;Acme Inc5&quot;
            orderby customer.Name
            select customer;

var result = query.ToList();
foreach (var item in result)
{
    Console.WriteLine(item.Name);
    Console.WriteLine(item.Address.City);
}
</pre></p>
<p>Will yield the following SQL + XPath query:</p>
<p><pre class="brush: sql;">
select *

from documents

where CollectionName = 'Customer' and
   ((documentdata.exist('/object/state/Address/object/state/City/text()[. = &quot;abc&quot;]') = 1) and
    (documentdata.exist('/object/state/Name/text()[. = &quot;Acme Inc5&quot;]') = 1))

order by documentdata.value('((/object/state/Name)[1])','nvarchar(MAX)')
</pre></p>
<p>The result of the query will be returned to the client and then deserialized into the correct .NET type.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/959/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/959/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/959/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/959/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/959/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/959/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/959/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/959/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=959&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/02/27/building-a-document-db-ontop-of-sql-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>
	</item>
		<item>
		<title>.NET disassembled Part 2: for loops</title>
		<link>http://rogeralsing.com/2011/02/10/net-disassembled-part-2-for-loops/</link>
		<comments>http://rogeralsing.com/2011/02/10/net-disassembled-part-2-for-loops/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 09:23:15 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[forloop]]></category>
		<category><![CDATA[jit]]></category>
		<category><![CDATA[native]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=936</guid>
		<description><![CDATA[.NET Disassembled Part 1: integers in .NET Part 2: This post This is my second post on .NET performance, in this series of posts I will try to show how .NET code performs compared to pure C++ code. Today I will show how a C# for loop compares to a Win32 C++ for loop. First we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=936&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>.NET Disassembled</strong><br />
Part 1: <a href="http://rogeralsing.com/2011/02/05/integers-in-net/">integers in .NET</a><br />
Part 2: This post</p>
<p>This is my second post on .NET performance, in this series of posts I will try to show how .NET code performs compared to pure C++ code.<br />
Today I will show how a C# for loop compares to a Win32 C++ for loop.</p>
<p>First we need some sample code to compare, so here it is:</p>
<p><strong>The C# code:</strong></p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/csforloopcode.png"><img class="alignnone size-full wp-image-939" title="csforloopcode" src="http://rogeralsing.files.wordpress.com/2011/02/csforloopcode.png?w=630" alt="" /></a></p>
<p><strong>The Win32 C++ code:</strong></p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/cppforloop.png"><img class="alignnone size-full wp-image-937" title="cppforloop" src="http://rogeralsing.files.wordpress.com/2011/02/cppforloop.png?w=630" alt="" /></a></p>
<p>I hope we can agree that the above code is fairly similair, we loop &#8220;i&#8221; from 0 to 999 and call the function &#8220;Foo&#8221; while doing so.</p>
<p>I will begin with the disassembly for the C++ code, just so we can see how optimized it is:</p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/nativefor.png"><img class="alignnone size-full wp-image-940" title="nativefor" src="http://rogeralsing.files.wordpress.com/2011/02/nativefor.png?w=630" alt="" /></a></p>
<p>What are we seeing here?<br />
The &#8220;i&#8221; variable have been replaced with a native register (esi) which is set to 1000.<br />
The Foo function have been inlined in the for loop.<br />
The loop guard have been optimized to &#8220;esi &#8211; ; if esi &gt;0 goto loopbody&#8221; since this is more efficient in native code (dec,jne)<br />
So the C++ code is clearly very optimized.</p>
<p>So how does the C# counterpart hold up against the optimized C++ code?<br />
<strong>[Edit] big thanks to Omer for pointing out how to disassemble the optimized .NET code.</strong></p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/optimizedcs.png"><img class="alignnone size-full wp-image-950" title="optimizedcs" src="http://rogeralsing.files.wordpress.com/2011/02/optimizedcs.png?w=630&#038;h=198" alt="" width="630" height="198" /></a></p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/csforloop.png"></a></p>
<p>Just like the C++ version, the variable &#8220;i&#8221; have been replaced with a native register, &#8220;esi&#8221;<br />
The Foo function call have been inlined (address 6-18), do note that calling console.writeline is not the same as calling cout in win32, so the code will differ.<br />
So the optimized .NET code is pretty much equal to the win32 C++ version.</p>
<p>Hope this can crush some of the myths floating around&#8230;</p>
<p>//Roger</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/936/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/936/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/936/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/936/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/936/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/936/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/936/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/936/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=936&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/02/10/net-disassembled-part-2-for-loops/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>

		<media:content url="http://rogeralsing.files.wordpress.com/2011/02/csforloopcode.png" medium="image">
			<media:title type="html">csforloopcode</media:title>
		</media:content>

		<media:content url="http://rogeralsing.files.wordpress.com/2011/02/cppforloop.png" medium="image">
			<media:title type="html">cppforloop</media:title>
		</media:content>

		<media:content url="http://rogeralsing.files.wordpress.com/2011/02/nativefor.png" medium="image">
			<media:title type="html">nativefor</media:title>
		</media:content>

		<media:content url="http://rogeralsing.files.wordpress.com/2011/02/optimizedcs.png" medium="image">
			<media:title type="html">optimizedcs</media:title>
		</media:content>
	</item>
		<item>
		<title>.NET disassembled Part 1: Integers in .NET</title>
		<link>http://rogeralsing.com/2011/02/05/integers-in-net/</link>
		<comments>http://rogeralsing.com/2011/02/05/integers-in-net/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 15:25:58 +0000</pubDate>
		<dc:creator>Roger Alsing</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://rogeralsing.com/?p=925</guid>
		<description><![CDATA[Today I attended one of Juval Löwy&#8217;s sessions on our inhouse conference. He argued that every object in .NET is a COM object behind the scenes, even Int32. Fair enough, Int32 is a type and it does have a Guid. The argument was an attempt to show that .NET is slow and that everything is pushed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=925&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I attended one of Juval Löwy&#8217;s sessions on our inhouse conference.</p>
<p>He argued that every object in .NET is a COM object behind the scenes, even Int32.<br />
Fair enough, Int32 is a type and it does have a Guid.<br />
The argument was an attempt to show that .NET is slow and that everything is pushed around as a COM object internally, even the integers&#8230;<br />
(This was an up ramp for his &#8220;every object should be a WCF service&#8221;, to show that performance doesn&#8217;t matter, much..)</p>
<p>This is however completely wrong..<br />
.NET have specific IL op codes in order to deal with primitives, and those opcodes will translate to pure machine code.</p>
<p>Here is a C# code snippet:</p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/csint.png"><img class="alignnone size-full wp-image-926" title="csint" src="http://rogeralsing.files.wordpress.com/2011/02/csint.png?w=630" alt=""   /></a></p>
<p>Here is the same code disassembled into x86</p>
<p><a href="http://rogeralsing.files.wordpress.com/2011/02/machinecodeint.png"><img class="alignnone size-full wp-image-927" title="machinecodeint" src="http://rogeralsing.files.wordpress.com/2011/02/machinecodeint.png?w=630" alt=""   /></a></p>
<p>The value hex 7B (dec 123) is moved directly into the memory slot for the local variable.<br />
No COM objects involved, no nothing, just normal machinecode, as long as you treat it as an int that is..<br />
You can not make this faster or better even if you resort to pure ASM.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rogeralsing.wordpress.com/925/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/rogeralsing.wordpress.com/925/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/rogeralsing.wordpress.com/925/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/rogeralsing.wordpress.com/925/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/rogeralsing.wordpress.com/925/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/rogeralsing.wordpress.com/925/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/rogeralsing.wordpress.com/925/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/rogeralsing.wordpress.com/925/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=rogeralsing.com&amp;blog=2473556&amp;post=925&amp;subd=rogeralsing&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://rogeralsing.com/2011/02/05/integers-in-net/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7ac3d313189eb4d3fe101e3aadcd08e2?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">roggan</media:title>
		</media:content>

		<media:content url="http://rogeralsing.files.wordpress.com/2011/02/csint.png" medium="image">
			<media:title type="html">csint</media:title>
		</media:content>

		<media:content url="http://rogeralsing.files.wordpress.com/2011/02/machinecodeint.png" medium="image">
			<media:title type="html">machinecodeint</media:title>
		</media:content>
	</item>
	</channel>
</rss>
