平均秒數測試
This commit is contained in:
parent
979cb30a7b
commit
9e150dd151
@ -84,6 +84,7 @@ namespace DualScreenDemo{
|
|||||||
connection.Close();
|
connection.Close();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒");
|
Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒");
|
||||||
|
writeLogforSearchTime(stopwatch.ElapsedMilliseconds);
|
||||||
Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。");
|
Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +98,9 @@ namespace DualScreenDemo{
|
|||||||
|
|
||||||
using (var connection = new MySqlConnection(connectionString))
|
using (var connection = new MySqlConnection(connectionString))
|
||||||
{
|
{
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
stopwatch.Start();
|
||||||
Console.WriteLine("MyDB 連線成功!");
|
Console.WriteLine("MyDB 連線成功!");
|
||||||
|
|
||||||
using (var command = new MySqlCommand(query, connection))
|
using (var command = new MySqlCommand(query, connection))
|
||||||
@ -121,11 +124,23 @@ namespace DualScreenDemo{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
connection.Close();
|
connection.Close();
|
||||||
Console.WriteLine("MyDB 連線已關閉!");
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"MyDB 連線已關閉!執行時間: {stopwatch.ElapsedMilliseconds} 毫秒");
|
||||||
|
writeLogforSearchTime(stopwatch.ElapsedMilliseconds);
|
||||||
|
Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。");
|
||||||
}
|
}
|
||||||
return searchResults;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user