You can use a class System.Diagnostics.Stopwatch.
Stopwatch sw = new Stopwatch();
sw.Start();
sw.Stop();
TimeSpan elapsed = sw.Elapsed;
Here you can use TimeSpan.Tickseither TimeSpan.TotalSecondsto determine past ticks or past seconds, respectively.
, , "" , ( , , , - - ..):
public static T ExecuteWithElapsedTime<T>(Func<T> function, out TimeSpan elapsedTime)
{
T rval;
Stopwatch sw = new Stopwatch();
sw.Start();
rval = function();
sw.Stop();
elapsedTime = sw.Elapsed;
return rval;
}
( myFunc - , int):
TimeSpan elapsed;
int result = ExecuteWithElapsedTime(myFunc, out elapsed);
, , .