net-logoSometimes you might want to knon how much time will it take to execute a certain process in C#. Here is a simple example to demonstrate how you can achieve this by using the TimeSpan attribute.
1
2
3
4
5
6
7
8
9
10
11
12
13
// clock the start time
DateTime start_time = DateTime.Now;

// To-do: Add you process here.

// clock the end time
DateTime end_time = DateTime.Now;

// get total seconds spend on the process
var total_seconds = (end_time - start_time).TotalSeconds;

// print the output
Console.WriteLine("Total seconds spent: {0}", total_seconds);