在這個例子中的代碼我使用的是簡單的秒錶來測試時,它需要完成特定任務的性能測試/動作Helper類使用秒錶類
StopWatch SW1 = new StopWatch();
SW1.Start();
SomeAction();
SW1.Stop();
sting results = SW1.Elapsed.ToString();
MessageBox.Show(resutls);
我想有一類,我將實例與測試
public Class PerformanceTests
{
public StopWatch SW1 = new StopWatch();
public StopWatch SW2 = new StopWatch();
public string results1 = "", results2 = "";
....
....
//some other variables to use
}
雖然實例化類,並嘗試使用SW1
是不是讓我使用它的方法時使用。我究竟做錯了什麼 ?
PerformanceTests Ptst = new PerformanceTests();
Ptst.SW1. ... Start() is not accessible
更新
答案的休息,不要將代碼從我複製,因爲我錯過資本stopwatch
。而不是實例化Stopwatch類,我不小心沒有注意到Visual Studio詢問我是否想爲我所謂的秒錶創建一個類,而不是.NET的真實Stopwatch
。
因此,我的建議是,儘管應始終保持相同,但請注意Visual Studio intellisense 的建議操作。只要確保直到你真的有經驗並且知道所有的課程。
'intelliSense'聽起來像蘋果產品。編輯,和許多 – nawfal
我在這裏寫了一個答案:http:// stackoverflow。com/questions/969290 /精確時間測量性能測試/ 16157458#16157458 另請參閱http://stackoverflow.com/questions/232848/wrapping-stopwatch-timing-with-a-delegate-or -lambda – nawfal