<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace Site Server v5.9.2 (http://www.squarespace.com/) on Wed, 10 Mar 2010 06:26:14 GMT--><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rss="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:cc="http://web.resource.org/cc/"><rss:channel rdf:about="http://www.chadmoran.com/blog/"><rss:title>Blog</rss:title><rss:link>http://www.chadmoran.com/blog/</rss:link><rss:description></rss:description><dc:language>en-US</dc:language><dc:date>2010-03-10T06:26:14Z</dc:date><admin:generatorAgent rdf:resource="http://www.squarespace.com/">Squarespace Site Server v5.9.2 (http://www.squarespace.com/)</admin:generatorAgent><rss:items><rdf:Seq><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/12/6/less-css-with-less-and-t4.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/8/1/im-over-here.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/6/1/where-has-all-the-content-gone.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/5/2/extension-method-digest-4-routebaseasroute.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/4/22/synthetic-followers-sign-of-something-deeper.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/4/21/optimizing-url-generation-in-aspnet-mvc-part-1.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/4/10/net-podcasts.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/4/4/linq-to-sql-is-not-dead-can-haz-dataz.html"/><rdf:li rdf:resource="http://www.chadmoran.com/blog/2009/4/3/ie8-ndash-almost-there.html"/></rdf:Seq></rss:items></rss:channel><rss:item rdf:about="http://www.chadmoran.com/blog/2009/12/6/less-css-with-less-and-t4.html"><rss:title>Less CSS with .LESS and T4!</rss:title><rss:link>http://www.chadmoran.com/blog/2009/12/6/less-css-with-less-and-t4.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-12-06T16:06:03Z</dc:date><dc:subject>.NET T4</dc:subject><content:encoded><![CDATA[<p>After hearing about <a href="http://www.dotlesscss.com/" target="_blank">.LESS</a> for .NET I was ecstatic.&nbsp; I&rsquo;ve been looking for something like this for quite some time.&nbsp; Recently <a href="http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx" target="_blank">Phil Haack blogged</a> about a T4 template he made using <a href="http://damieng.com/blog/2009/11/06/multiple-outputs-from-t4-made-easy-revisited" target="_blank">Damien Guard&rsquo;s helper class</a> to generate CSS files for each LESS file.&nbsp; This way it would generate static CSS files you could reference.</p>
<p>As great as this was I personally was looking to just have the CSS files appear in the location of the LESS files making it easier to reference/view the CSS files.&nbsp; The advantage to this is if you have CSS files in a particular directory structure they will be exactly where the LESS files are thus keeping your structure.</p>
<p>For this I utilize <a href="http://www.codeplex.com/t4toolbox" target="_blank">T4 Toolbox</a> which is a great library that helps with doing some normally painful tasks in T4 fairly easy.&nbsp; An example of this is being able to have multiple output files and being able to set their locations which is what makes this possible.&nbsp; To use this T4 template ensure you&rsquo;ve installed the T4 Toolbox then just drop it in your project directory.&nbsp; For the sake of making this work with Phil&rsquo;s example the assembly references expect the <a href="http://www.dotlesscss.com/" target="_blank">.LESS</a> and <a href="http://www.codeplex.com/YUICompressor" target="_blank">YUI Compressor</a> libraries to be in the solution&rsquo;s root directory.&nbsp; You can change this to fit your needs.</p>
<pre class="brush: csharp;">&lt;#@ template language="C#" hostspecific="True" #&gt;
&lt;#@ output extension="log" #&gt;
&lt;#@ include file="T4Toolbox.tt" #&gt;
&lt;#@ assembly name="$(ProjectDir)\..\dotless.Core.dll" #&gt;
&lt;#@ assembly name="$(ProjectDir)\..\Yahoo.Yui.Compressor.dll" #&gt;
&lt;#@ import namespace="dotless.Core" #&gt;
&lt;#@ import namespace="Yahoo.Yui.Compressor" #&gt;
&lt;#@ import namespace="System.IO" #&gt;

&lt;#
    bool compress = false;
#&gt;

&lt;#
    var currentDirectory = Path.GetDirectoryName(Host.TemplateFile);
    var lessFiles = Directory.GetFiles(currentDirectory, "*.less", SearchOption.AllDirectories);
    
    foreach (var lessFile in lessFiles)
    {
        string file = Path.Combine(Path.GetDirectoryName(lessFile), Path.GetFileNameWithoutExtension(lessFile) + ".css");
        
        Write("* Converting {0} to {1}", lessFile, file);
        
        LessTemplate template = new LessTemplate(lessFile, compress);
        template.Output.File = file;
        template.Render();
    }
#&gt;

&lt;#+
public class LessTemplate : Template
{    
    private static ExtensibleEngine DotLess = new ExtensibleEngine();
    
    protected bool Compress { get; set; }
    protected string File { get; set; }
    
    public LessTemplate(string file, bool compress)
    {
        File = file;
        Compress = compress;
    }
    
    public override string TransformText()
    {
        string css = DotLess.TransformToCss(File);
        
        if (Compress)
            css = CssCompressor.Compress(css);
        
        Write(css);
        return this.GenerationEnvironment.ToString();
    }
}
#&gt;</pre>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/8/1/im-over-here.html"><rss:title>I'm over here!</rss:title><rss:link>http://www.chadmoran.com/blog/2009/8/1/im-over-here.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-08-01T22:35:32Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>I'd first like to thank the people that are still subscribed to my feed after being absent for so long.&nbsp; Finding a full-time job was priority #1.&nbsp; I'm glad to report I found one after only 2-3 weeks of searching.</p>
<p>I wound up getting a job with Curse, Inc.&nbsp; If you play an MMO chances are you know who Curse is.&nbsp; They own and operate sites like www.curse.com www.wowace.com www.worldofraids.com and so forth.&nbsp; They're a great company with a lot of talent and direction.&nbsp; I came onto the team during a project that is being built on ASP.NET MVC which is great since I've been following it since it's birth back in 2007.&nbsp; It's a great oppurtunity and honor to work with Curse and my fellow co-workers.</p>
<p>I'd like to get started on an open-source project for the community that I can work on during the weekends so we'll see how that turns out.&nbsp; But I do promise starting next week I'll start my regular posting again.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/6/1/where-has-all-the-content-gone.html"><rss:title>Where has all the content gone?</rss:title><rss:link>http://www.chadmoran.com/blog/2009/6/1/where-has-all-the-content-gone.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-06-01T16:03:36Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>I feel bad with more and more people following my blog that I'm not able to keep up with my posts but I do have a reason, I promise!</p>
<p>I've been self-employed however due to clients drying up I've been looking for a full time job as a .NET dev and have been extremely busy with writing demo code and trying to find work.&nbsp; If you know of anyone looking for a .NET dev feel free to forward them to me through my Contact page or e-mail me at chad dot moran at live dot com.</p>
<p>I have some great content writting up including the third part of my ASP.NET MVC URL generation optimization and another great post about how I found a problem with a common workaround for ASP.NET MVC output caching that could cause way more memory usage than required.</p>
<p>I'll try to pump out these posts as soon as possible and my apologies for not getting them out sooner.&nbsp; Thanks for reading and hope to write again soon.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/5/2/extension-method-digest-4-routebaseasroute.html"><rss:title>Extension method digest #4 RouteBase.AsRoute</rss:title><rss:link>http://www.chadmoran.com/blog/2009/5/2/extension-method-digest-4-routebaseasroute.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-05-02T17:14:51Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>This one is very simple but is extremely helpful when dabbling in the System.Web.Routing namespace.&#160; Using AsRoute extension will allow you to get to the properties and methods on the Route type itself like Constraints, Defaults and Url.</p>  <pre class="brush: csharp;">public static class RouteBaseExtensions<br />{<br />    public static Route AsRoute(this RouteBase routeBase)<br />    {<br />        return routeBase as Route;<br />    }<br />}</pre><p>Again, a very simple extension method that can help save some time instead of having to cast the object yourself.&#160; If the RouteBase target isn’t a Route itself it will just return null.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html"><rss:title>Optimizing URL generation in ASP.NET MVC – Part 2</rss:title><rss:link>http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-04-23T17:48:50Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p><a href="http://www.chadmoran.com/blog/2009/4/21/optimizing-url-generation-in-aspnet-mvc-part-1.html">Part 1</a> <br />Part 2</p>
<p>So in continuing with the series of URL generation optimization in ASP.NET MVC we&rsquo;re going to take a look at the actual optimization part of things.</p>
<p>Before I get started I&rsquo;d like to start off by saying the results of the first part&rsquo;s test were a little off due to my mistake.&nbsp; When I was setting up the routes I didn&rsquo;t setup defaults for the default route (&ldquo;/&rdquo;) so the URLs actually being generated were /name=chad&amp;age=23 instead of /Home/Index/Chad/23 and thus skewing the results so to fix that I&rsquo;ll be running the first 5 all over again including 3 new ones.&nbsp; Note that the expression syntax method was not changed from this and the performance still stands.&nbsp; The only methods that were really affected by this were those that found the route by action and controller names.&nbsp; I apologize for the mistake and I will update the post accordingly.</p>
<p>In the <a href="http://www.chadmoran.com/blog/2009/4/21/optimizing-url-generation-in-aspnet-mvc-part-1.html">first part</a> we looked at some methods that are probably most commonly used by ASP.NET MVC devs and this part I&rsquo;d like to look at some lesser-used methods of getting these URLs generated.&nbsp; In this part I&rsquo;m going to go over 2 other methods of getting URLs generated.&nbsp; Though these methods might not generate all of the HTML they&rsquo;re just as useful and even faster than previous methods.</p>
<p>Url.Action using action name and anonymous object (Method 6)</p>
<pre class="brush: csharp;">Url.Action("Index", new { name = "Chad", age = 23 })</pre>
<p>Url.Action using action name, controller name and anonymous object (Method 7)</p>
<pre class="brush: csharp;">Url.Action("Index", "Home", new { name = "Chad", age = 23 })</pre>
<p>Url.RouteUrl using route name and anonymous object (Method 8)</p>
<pre class="brush: csharp;">Url.RouteUrl("HomeIndex", new { name = "Chad", age = 23 })</pre>
<p>Same conditions as the the first part.&nbsp; After thinking about it I should have put these tests into the first part but what can you do so here they are.&nbsp; Before the results I&rsquo;d like to point out these methods don&rsquo;t generate the whole URL rather the part after the TLD.&nbsp; So in a URL like <a href="http://mydomain.com/Home/Index">http://mydomain.com/Home/Index</a> these methods would only generate the /Home/Index parts.&nbsp; I understand this isn&rsquo;t the same as the previous methods but they can still be used the same.&nbsp; Only differences is you would have to wrap them in your own HTML (blasphemy, I know).&nbsp; It would look something like this.</p>
<pre class="brush: xml;">&lt;a href="&lt;% Url.RouteUrl("HomeIndex", new { name = "Chad", age = 23 }); %&gt;"&gt;Link&lt;/a&gt;</pre>
<p>Now for the results.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="URL Generation test" src="http://www.chadmoran.com/resource/WindowsLiveWriter/OptimizingURLgenerationinASP.NETMVCPart2_B5F0/?fileId=2942151" border="0" alt="URL Generation test" width="551" height="291" /></p>
<p>As you can see there was actually a difference between using action name and controller name versus using route names in performance like I originally suspected there should have been.</p>
<p>This is where the second part of this series should have started considering those 3 last tests should have been in the last one.</p>
<p>In the <a href="http://www.chadmoran.com/blog/2009/4/21/optimizing-url-generation-in-aspnet-mvc-part-1.html">first part</a> I linked to a great presentation that showed off how you can improve URL generation performance by not using the expression syntax and not using anonymous objects.&nbsp; I&rsquo;d also like to cover that.</p>
<p>When you use method 1 for URL generation it has to get the parameter values from your expression and put them into a <a href="http://msdn.microsoft.com/en-us/library/system.web.routing.routevaluedictionary.aspx">RouteValueDictionary</a> and pass that into another method to get the URL.&nbsp; The method it uses is a nasty one (not coded badly but, expensive).&nbsp; This method is in Microsoft.Web.Mvc.Internal.ExpressionHelper class.</p>
<pre class="brush: csharp; highlight: [17,18];">private static void AddParameterValuesFromExpressionToDictionary(RouteValueDictionary rvd, MethodCallExpression call)<br />{<br />    ParameterInfo[] parameters = call.Method.GetParameters();<br />    if (parameters.Length &gt; 0)<br />    {<br />        for (int i = 0; i &lt; parameters.Length; i++)<br />        {<br />            Expression expression = call.Arguments[i];<br />            object obj2 = null;<br />            ConstantExpression expression2 = expression as ConstantExpression;<br />            if (expression2 != null)<br />            {<br />                obj2 = expression2.Value;<br />            }<br />            else<br />            {<br />                Expression&lt;Func&lt;object&gt;&gt; expression3 = Expression.Lambda&lt;Func&lt;object&gt;&gt;(Expression.Convert(expression, typeof(object)), new ParameterExpression[0]);<br />                obj2 = expression3.Compile()();<br />            }<br />            rvd.Add(parameters[i].Name, obj2);<br />        }<br />    }<br />}</pre>
<p>As you can see on lines 17 and 18 this is getting called for <strong>every</strong> parameter coming into your method.&nbsp; If you have a method with more parameters performance would be affected.&nbsp; I decided to run a test on this too and see how performance would be changed as you add parameters onto your actions.&nbsp; Again, same conditions used as the all other tests.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Expression syntax test" src="http://www.chadmoran.com/resource/WindowsLiveWriter/OptimizingURLgenerationinASP.NETMVCPart2_B5F0/?fileId=2941770" border="0" alt="Expression syntax test" width="551" height="291" /></p>
<p>As you can see performance gets thrown out the door as you add more and more parameters to the action method.</p>
<p>So that&rsquo;s what is killing performance in the expression syntax of URL generation.&nbsp; What about the other methods, what could be hurting their performance?&nbsp; The main performance loss in all other methods is using anonymous objects.&nbsp; When you use an anonymous object for your route parameter values it has to use reflection to put them into a RouteValueDictionary and this is how it&rsquo;s done.</p>
<pre class="brush: csharp;">private void AddValues(object values)<br />{<br />    if (values != null)<br />    {<br />        foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))<br />        {<br />            object obj2 = descriptor.GetValue(values);<br />            this.Add(descriptor.Name, obj2);<br />        }<br />    }<br />}</pre>
<p>So again, reflection is happening for each parameter passed in so the same performance decrease would happen with all other methods when adding more parameters.</p>
<p>To get around this we can just pass in our own RouteValueDictionary to avoid having to any reflection and it&rsquo;s pretty easy to do.&nbsp; So we&rsquo;ll run the same 9 tests as before but without using anonymous objects and see what kind of difference we see.</p>
<p>Html.ActionLink&lt;&gt; expression (Method 1)</p>
<pre class="brush: csharp;">Html.ActionLink&lt;HomeController&gt;(c =&gt; c.Index("Chad", 23), "Link")</pre>
<p>&nbsp;</p>
<p>Html.ActionLink using action name and RouteValueDictionary (Method 2)</p>
<pre class="brush: csharp;">Html.ActionLink("Link", "Index", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } })</pre>
<p>Html.ActionLink using action name, controller name and RouteValueDictionary (Method 3)</p>
<pre class="brush: csharp;">Html.ActionLink("Link", "Index", "Home", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } }, null)</pre>
<p>Html.RouteLink using RouteValueDictionary (Method 4)</p>
<pre class="brush: csharp;">Html.RouteLink("Link", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } })</pre>
<p>Html.RouteLink using named route and RouteValueDictionary (Method 5)</p>
<pre class="brush: csharp;">Html.RouteLink("Link", "HomeIndex", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } })</pre>
<p>Url.Action using action name and RouteValueDictionary (Method 6)</p>
<pre class="brush: csharp;">Url.Action("Index", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } })</pre>
<p>Url.Action using action name, controller name and RouteValueDIctionary (Method 7)</p>
<pre class="brush: csharp;">Url.Action("Index", "Home", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } })</pre>
<p>Url.RouteUrl using route name and RouteValueDictionary (Method 8)</p>
<pre class="brush: csharp;">Url.RouteUrl("HomeIndex", new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } })</pre>
<p>TIme to run the tests&hellip;</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="URL Generation test" src="http://www.chadmoran.com/resource/WindowsLiveWriter/OptimizingURLgenerationinASP.NETMVCPart2_B5F0/?fileId=2942431" border="0" alt="URL Generation test" width="551" height="291" /></p>
<p>I put method 1 there for consistency.&nbsp; The rest saw a pretty substantial boost in performance.&nbsp; The most was Method 5 going from 282 to 120 ms, that&rsquo;s more than double boost in performance.</p>
<p>As you can see the difference was going from this&hellip;</p>
<pre class="brush: csharp;">new { name = "Chad", age = 23 }</pre>
<p>To this&hellip;</p>
<pre class="brush: csharp;">new RouteValueDictionary { { "name", "Chad" }, { "age", 23 } }</pre>
<p>Again, I&rsquo;m sure there are those out there that will point out this looks like a pain to write these types of links with this code and I agree.&nbsp; That&rsquo;s why in the next part I&rsquo;m going to go over how we can get intellisense and maintainability over our code when generating URLs.&nbsp; I am fully aware that this is only a difference of 100ms~ over 10,000 links but this can be very helpful with high-volume sites and sites that generate a large amount of URLs per page.</p>
<p>So now we&rsquo;ve seen which methods are fastest and how we can make them twice as fast.&nbsp; In the next part of the series I&rsquo;ll go over how we can utilize this faster code and still keep it maintainable and easy to use.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/4/22/synthetic-followers-sign-of-something-deeper.html"><rss:title>Synthetic followers, sign of something deeper?</rss:title><rss:link>http://www.chadmoran.com/blog/2009/4/22/synthetic-followers-sign-of-something-deeper.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-04-22T17:37:11Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>Lately I’ve noticed an abnormal amount of people following me and shortly after I decided to follow them back unfollow me.&#160; I mean, really?</p>  <p>I don’t know this just angers me and makes me feel bad for that person at the same time.&#160; If you really want people to follow you write interesting information don’t trick people into following you.&#160; I get about 2-5 spam followers a day if you want I can forward them and you can have your own little following.</p>  <p>Maybe I’m seeing twitter from a different light but for some people followers are like WoW achivements or StackOverflow reputation points – they’re just addicting.&#160; Seriously though, I think this shows a lot about a person that they feel the need to get synthetic followers.&#160; What I mean by that is, non-organic followers.&#160; People that were tricked into following someone by some sort of mechanism.</p>  <p>Now I’m sure there are people out there who go follow happy and change their mind.&#160; I guess excuses are like belly buttons… everyone has one.</p>  <p>&lt;/rant&gt;</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/4/21/optimizing-url-generation-in-aspnet-mvc-part-1.html"><rss:title>Optimizing URL generation in ASP.NET MVC – Part 1</rss:title><rss:link>http://www.chadmoran.com/blog/2009/4/21/optimizing-url-generation-in-aspnet-mvc-part-1.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-04-21T16:44:23Z</dc:date><dc:subject>ASP.NET MVC Performance</dc:subject><content:encoded><![CDATA[<p>Part 1<br /><a href="http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html">Part 2</a></p>
<p>Inspired by a great presentation by Rudi Benkovic I thought I would make a series of blog posts about improving ASP.NET MVC performance through URL generation.</p>
<p>While developing an application for a project of mine I went gung-ho with expressions wherever I could.&nbsp; Whether it was methods in my controllers or URL generation they were everywhere.&nbsp; While stress-testing my app I ramped up the items on a page and noticed performance dipped significantly.&nbsp; At the time I thought it may have been the data access since I&rsquo;ve had troubles before with LINQ to SQL performance.&nbsp; Though I found out it was actually the URL generation.&nbsp; I was using the expression syntax from MvcFutures that looked like this.</p>
<pre class="brush: csharp;">Html.ActionLink&lt;HomeController&gt;(c =&gt; c.Index())</pre>
<p>This is great if you want compile-time checking by compiling your views.&nbsp; Problem is, this is horribly inefficient.&nbsp; Let&rsquo;s compare it against some other methods of linking.&nbsp; I&rsquo;m going to be creating a brand new ASP.NET MVC Project for those that want to follow along.&nbsp; I&rsquo;ll be modifying the Index action of the Home controller for the sake of testing.</p>
<pre class="brush: csharp;">public ActionResult Index(string name, int age)<br />{<br />    ViewData["Message"] = string.Format("Hello {0}.  I see you're {1} year(s) old.");<br /><br />    return View();<br />}</pre>
<p>I added to parameters to the Index controller so we can test passing arguments into the method as part of the performance testing.&nbsp; I added the following to web.config</p>
<pre class="brush: xml;">&lt;add namespace="Microsoft.Web.Mvc"/&gt;<br />&lt;add namespace="URLGeneration"/&gt;<br />&lt;add namespace="System.Diagnostics"/&gt;</pre>
<p>I also added the following routes to the list.&nbsp; The reason I added them individually is to simulate a site having a few routes.&nbsp; Putting the one we want to use at the bottom.</p>
<pre class="brush: csharp;">routes.MapRoute(<br />    "Default",<br />    "",<br />    new { controller = "Home", action = "Index" }<br />);<br /><br />routes.MapRoute(<br />    "AccountChangePassword",<br />    "Account/ChangePassword",<br />    new { controller = "Account", action = "ChangePassword" }<br />);<br /><br />routes.MapRoute(<br />    "AccountChangePasswordSuccess",<br />    "Account/ChangePasswordSuccess",<br />    new { controller = "Account", action = "ChangePasswordSuccess" }<br />);<br /><br />routes.MapRoute(<br />    "AccountLogOn",<br />    "Account/LogOn",<br />    new { controller = "Account", action = "LogOn" }<br />);<br /><br />routes.MapRoute(<br />    "AccountRegister",<br />    "Account/Register",<br />    new { controller = "Account", action = "Register" }<br />);<br /><br />routes.MapRoute(<br />    "HomeAbout",<br />    "Home/About",<br />    new { controller = "Home", action = "About" }<br />);<br /><br />routes.MapRoute(<br />    "HomeIndex",<br />    "Home/Index/{name}/{age}",<br />    new { controller = "Home", action = "Index" }<br />);</pre>
<p>The name of the project I created was URLGeneration thus the namespace.&nbsp; Now the code for testing URL generation performance.</p>
<pre class="brush: csharp;">&lt;%<br />    Stopwatch sw = Stopwatch.StartNew();<br />    for (int i = 0; i &lt; 10000; i++)<br />    {<br />        %&gt;&lt;%= // URL generation %&gt;&lt;%<br />    }<br />    sw.Stop();<br />    %&gt;&lt;%= sw.ElapsedMilliseconds %&gt;&lt;%<br />%&gt;</pre>
<p>This code is pretty straight forward and should allow for accurate testing.&nbsp; I&rsquo;ll be running this code on a dedicated server with nothing else running and to help accuracy I&rsquo;ll run the test 5 times and average out the time.&nbsp; This will ensure we&rsquo;re testing JUST the URL generation time and not the rest of the page or transfer time.&nbsp; Some of you might be thinking 10,000 seems like a high number and you&rsquo;ll never have that many links on your site.&nbsp; Well, you&rsquo;re right but if you have a lot of requests coming in at a given time then you may be generating that many overall.&nbsp; This will help spread out the difference between the tests.</p>
<p>The methods of URL generation will be the following, probably most used methods first.</p>
<p>Html.ActionLink&lt;&gt; expression (Method 1)</p>
<pre class="brush: csharp;">Html.ActionLink&lt;HomeController&gt;(c =&gt; c.Index("Chad", 23), "Link")</pre>
<p>Html.ActionLink using action name and anonymous object (Method 2)</p>
<pre class="brush: csharp;">Html.ActionLink("Link", "Index", new { name = "Chad", age = 23 })</pre>
<p>Html.ActionLink using action name, controller name and anonymous object (Method 3)</p>
<pre class="brush: csharp;">Html.ActionLink("Link", "Index", "Home", new { name = "Chad", age = 23 }, null)</pre>
<p>Html.RouteLink using anonymous object for guessing route (Method 4)</p>
<pre class="brush: csharp;">Html.RouteLink("Link", new { name = "Chad", age = 23 })</pre>
<p>Html.RouteLink using named route (Method 5)</p>
<pre class="brush: csharp;">Html.RouteLink("Link", "HomeIndex", new { name = "Chad", age = 23 })</pre>
<p>I ran all tests after a couple of warm-up loads.&nbsp; None of the runs were on a cold start.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="test1" src="http://www.chadmoran.com/resource/WindowsLiveWriter/Test_947D/?fileId=2924627" border="0" alt="test1" width="551" height="291" /></p>
<p><strong>UPDATE</strong> These results were actually skewed due to a mistake I made in the the default route.&nbsp; To see updated, correct results please check out the <a href="http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html">second part</a> of this series.</p>
<p>As you can see the method in MvcFutures is 10x as slow as the others.&nbsp; I was actually surprised about Method 5 I thought that it would have been the fastest.</p>
<p>Now you may be thinking, well you tested 10,000 links and you&rsquo;re right.&nbsp; Let&rsquo;s say you have 10 links and 1,000 requests coming in (which isn&rsquo;t a lot for high-volume sites) then you&rsquo;re adding 2 <strong>seconds</strong> in processing time just to generate links.&nbsp; This was not the time it took to generate the whole page just the links.&nbsp; That&rsquo;s a lot of time to be adding meaning your requests/sec is going to dip.</p>
<p>In the next installment I&rsquo;ll go over how we can go about optimizing this performance and how much of an impact it can have with some load testing.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/4/10/net-podcasts.html"><rss:title>.NET Podcasts</rss:title><rss:link>http://www.chadmoran.com/blog/2009/4/10/net-podcasts.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-04-10T14:00:00Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>I’ve had a lot of people ask me what podcasts I listen to lately so instead of answering everyone seperately I figured I would also just write up a post about it instead (in no particular order).</p>  <p><a href="http://www.dotnetrocks.com/">.NET Rocks!</a>    <br />This is an obvious pick with hosts Carl Franklin and Richard Campbell they have a great section of the podcast called “better know framework,” which sheds some light on an otherwise feature in the dark corner.</p>  <p><a href="http://itc.conversationsnetwork.org/series/stackoverflow.html">StackOverflow podcast</a>    <br />I decided to list this because though this may not be a .NET podcast I have learned a lot of great .NET related things by listening to it.</p>  <p><a href="http://deepfriedbytes.com/">Deep Fried Bytes</a>    <br />Another great .NET podcast with a bit of southern hospitality and fried food!</p>  <p><a href="http://www.hanselminutes.com/">Hanselminutes</a>    <br />This one is just, obvious.</p>  <p><a href="http://herdingcode.com/">Herding Code</a>    <br />Herding Code is a great podcast that talks about those edge cases we all fear.</p>  <p><a href="http://polymorphicpodcast.com/">Polymorphic podcast</a>    <br />They don’t update on a regular schedule but another great podcast.</p>  <p><a href="http://sqlserverpedia.com/blog/">SQLServerPedia</a>    <br />This one is a video podcast with Brent Ozar an amazing SQL ninja.</p>  <p>I obviously listen to a lot more but these are the ones related to the questions I tend to get.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/4/4/linq-to-sql-is-not-dead-can-haz-dataz.html"><rss:title>LINQ to SQL is not dead - can haz dataz</rss:title><rss:link>http://www.chadmoran.com/blog/2009/4/4/linq-to-sql-is-not-dead-can-haz-dataz.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-04-04T19:46:44Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>A lot of conversations I’ve had with people lately always seem to have the, now obligatory “Well, LINQ to SQL is dead so…”.&#160; It’s really starting to get monotonous how many times a day I hear this said by someone.</p>  <p><a href="http://twitter.com/johnsheehan/status/1452588290">According to John Sheehan</a> who’s attending <a href="http://www.twincitiescodecamp.com/TCCC/Default.aspx">Twin Cities Code Camp</a> even <strong><em>presenters</em></strong> are informing their session attendee’s that LINQ to SQL is dead.</p>  <p>I’m going to make this as simple as possible.&#160; It’s not.</p>  <p>While I was attending MIX09 in March I had dinner with Scott Hanselman along with some other attendee’s of the conference.&#160; One of the topics that came up was LINQ to SQL and Scott had mentioned that there are currently 5 developers on the LINQ to SQL team.&#160; That’s 2 more than the current 3 on the ASP.NET MVC team.&#160; For a dead project, that would be a lot of man hours to waste.</p>  <p>So, please inform your fellow developers, dbas and friends that LINQ to SQL is not dead.</p>]]></content:encoded></rss:item><rss:item rdf:about="http://www.chadmoran.com/blog/2009/4/3/ie8-ndash-almost-there.html"><rss:title>IE8 &amp;ndash; Almost there</rss:title><rss:link>http://www.chadmoran.com/blog/2009/4/3/ie8-ndash-almost-there.html</rss:link><dc:creator>Chad Moran</dc:creator><dc:date>2009-04-03T20:49:09Z</dc:date><dc:subject></dc:subject><content:encoded><![CDATA[<p>When I was at MIX09 they announced the official release of IE8 which was kind of expected.&#160; I thought I’d reformat my my machine back to Vista so I could give it a fair try (can’t upgrade to IE8 RTW under Windows 7).&#160; So I went about and installed it and I’ll be honest, I love it.&#160; It’s fast for a browser from the Internet Explorer brand.&#160; I could go on for a while describing while I think it’s great but to be honest I think it’s currently at where it <strong><em>should be</em></strong> and I hope the next version of IE will finally raise the bar for browsers.</p>  <p>While at MIX I had a lot of talks with Scott Hanselman about accessibility because I have very poor eyesight.&#160; One of the features he mentioned I would love is the full page zoom in IE8.&#160; Well, to be honest Firefox already does this and is one of the main reasons Firefox is my default browser.&#160; I noticed about 4 minutes into using it that when you select a full page zoom level it is selected as IE8’s global setting and cannot be set on a site by site basis.&#160; I like to zoom different pages differently depending on things like text size, whether to not they overflow and create a horizontal scroll bar and if they get distorted by zooming.</p>  <p>The only other reason I’m really not using IE8 as my default browser full time is due to the fact that I can’t get a full fledge firebug under IE8.&#160; Now I know, I know there is the developer tools tool that comes with IE8 but it’s missing the net tab.&#160; Other than that I’d say it’s almost more feature-rich than Firebug.</p>  <p>The IE8 team did a fantastic job with bringing the quality of IE up with the rest of the other browsers out there.&#160; I hope that with vNext they can add at least one of the two features I’m looking for.&#160; If they added the site by site zoom setting I would probably use it as my default browsing browser(hah).</p>]]></content:encoded></rss:item></rdf:RDF>