Question: What is the best way to measure speed of functions and classes? For every function there are various solutions and I'd like to know how to measure running speed and optimize my shared classes with the best solution possible. 

Also how do you measure SQL speed, for example differences between stored procedures, selects, views and etc.?

Answer: 
You have two options.

**Use [`System.Diagnostics.Stopwatch`](http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx) for specific methods.**

This is a high resolution timer in .NET which you can use for specific parts of your code.

**Use a profiler if you need to measure performance for your entire application.**

You can use the build in profiler of the Ultra edition of Visual Studio, or a tool like [EQATEC](http://www.eqatec.com/).
You're best off using a profiler. The problem with measuring wallclock execution time (such as done by the `Stopwatch` class) is that it is influenced by many factors far out of your control. To mention just a few such factors, there's network and other I/O latency, and operating system scheduler decisions which influence the relative priority of applications and threads. If you are running inside a virtualized environment, that can also have a comparatively large effect on millisecond-range wallclock time measurements. The profiler won't be perfect, but it will give you a better idea of how much time is actually spent executing your code.

Besides that, a good profiler can often give you other useful metrics as well, like how much memory your code uses during execution.