Timing code within functions in Unity

I had to time some C# code within a function in Unity3D. Without the professional version of Unity, you don’t have a profiler. The code I used was the following:

long startTime = DateTime.UtcNow.Ticks;

// some code you want to time

long now = DateTime.UtcNow.Ticks;
long tm1 = now - startTime;
startTime = now;

// more code you want to time

now = DateTime.UtcNow.Ticks;
long tm2 = now - startTime;
startTime = now;

// etc
Debug.Log("tm1 = " + tm1);
Debug.Log("tm2 = " + tm2);

This worked for me and enable me to determine which part of the code was taking the time (not the part that I was expecting!).

There may be better ways to do this, but this worked for me.