Question: Like most of us, I am a big fan of improving efficiency of code. So much so that I would rather choose fast-executing dirty code over something which might be more elegant or clean, but slower. 

Fortunately for all of us, in most cases, the faster and more efficient solutions are also the cleaner and the most elegant ones. I used to be just a dabbler in programming but I am into full-time development now, and just started with C# and web development. I have been reading some good books on these subjects but sadly, books rarely cover the finer aspects. Like say, which one of two codes which do the same thing will run faster. This kind of knowledge comes mostly through experience only. I request all fellow programmers to share any such knowledge here.

Here, I'll start off with these two blog posts I came across. This is exactly the kind of stuff I am looking for in this post:

* [Stringbuilder vs String performance analysis](http://blog.maartenballiauw.be/post/2008/02/Code-performance-analysis-in-Visual-Studio-2008.aspx)
* [The cost of throwing an exception](http://www.codinghorror.com/blog/2005/08/tryparse-and-the-exception-tax.html)

P.S: Do let me know if this kind of thing already exists somewhere on this site. I searched but couldn't find, surprisingly. Also please post any book you know of that covers such things.

P.P.S: If you got to know of something from some blog post or some online source to which we all have access, then it would be better to post the link itself imo.

Answer: 
The single most important thing regarding this question is: Don't optimize prematurely!

There is only one good time to optimize and that is when there are performance constraints that your current working implementation cannot fulfill. Then you should get out a profiler and check which parts of your code are slow and how you can fix them. 

Thinking about optimization while coding the first version is mostly wasted time and effort.
There are lots of tricks, but if that's what you're thinking you need, you need to start over. The secret of performance in any language is not in coding techniques, it is in **finding what to optimize**.

To make an analogy, if you're a police detective, and you want to put robbers in jail, the heart of your business is not about different kinds of jails. It is about *finding the robbers*.

I rely on a purely manual method of profiling. [This is an example](https://stackoverflow.com/questions/926266/performance-optimization-strategies-of-last-resort/927773#927773) of finding a series of points to optimize, resulting in a speedup multiple of *43 times*.

If you do this on an existing application, you are likely to discover that the main cause of slow performance is overblown data structure design, resulting in an excess of notification-style consistency maintenance, characterized by an excessively bushy call tree. You need to find the calls in the call tree that cost a lot and that you can prune.

Having done that, you may realize that a way of designing software that uses the bare minimum of data structure and abstractions will run faster to begin with.