I've discovered (by accident) that the last CLR does the tail call optimization. I have tested it with a piece of code, but frankly it doesn't behave the way I expected. I thought the tail call optimization may happen when the last thing in the function is a function call.
I'm trying to "break" this code to prevent form tail call op.
class Program
{
    static void Foo(int counter, int limit)
    {
        try
        {
            if (counter == limit)
            {
                return;
            }
            Foo(++counter, limit);
            int d = 1;
            d = Bar(d);
            //Console.Write(d);
            //Thread.Sleep(1);
            int baz = 0;
            var z = baz + d;
            StringBuilder b = new StringBuilder();
            b.Append("D");
        }
        catch (Exception)
        {
            throw;
        }
    }
    static int Sum(int s)
    {
        if (s == 1)
        {
            return s;
        }
        return s + Sum(s - 1);
    }
    static int Bar(int d)
    {
      return  d = 10 + d;
    }
    static void Main(string[] args)
    {
        int i = 0;
        Foo(i, 10000); // jitter 
        Sum(10000);
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        Foo(i, 10000);
        stopwatch.Stop();
        Console.WriteLine(string.Format("time of execution = {0}ms",stopwatch.ElapsedMilliseconds));
        stopwatch = new Stopwatch();
        stopwatch.Start();
        Sum(10000);
        stopwatch.Stop();
        Console.WriteLine(string.Format("time of execution = {0}ms", stopwatch.ElapsedMilliseconds));
        Console.ReadKey();
    }
}
Yet still Foo is optimized. How come?
 
     
    