有沒有一種方法(C#中的類)可以讓我計算在程序中執行某些行所需的時間。計算一行或多行代碼的執行時間
例:
try
{
string connectionString = GetConnectionString();
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
***// start counting:
// time = 0***
using (SqlCommand cmd = new SqlCommand(
「SELECT * FROM Books」, conn))
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(「{0}\t{1}\t{2}」,
reader.GetInt32(0),
reader.GetString(1),
reader.GetInt32(2));
}
***// end counting
// time = 10 sec***
}
}
它應該是秒錶「小後衛」,謝謝! – Shadi