平均秒數測試

This commit is contained in:
jasonchenwork 2025-04-15 11:31:02 +08:00
parent 979cb30a7b
commit 9e150dd151

View File

@ -84,6 +84,7 @@ namespace DualScreenDemo{
connection.Close();
stopwatch.Stop();
Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒");
writeLogforSearchTime(stopwatch.ElapsedMilliseconds);
Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。");
}
@ -97,7 +98,9 @@ namespace DualScreenDemo{
using (var connection = new MySqlConnection(connectionString))
{
Stopwatch stopwatch = new Stopwatch();
connection.Open();
stopwatch.Start();
Console.WriteLine("MyDB 連線成功!");
using (var command = new MySqlCommand(query, connection))
@ -121,11 +124,23 @@ namespace DualScreenDemo{
}
}
connection.Close();
Console.WriteLine("MyDB 連線已關閉!");
stopwatch.Stop();
Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒");
writeLogforSearchTime(stopwatch.ElapsedMilliseconds);
Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。");
}
return searchResults;
}
private int countforSearch = 0;
private void writeLogforSearchTime(long elapsedMs){
countforSearch++;
string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "txt", "searchTimeLog.txt");
string data = $"{countforSearch}, {elapsedMs} " + Environment.NewLine;
File.AppendAllText(logFilePath, data);
}
}
}