【轉】Visual Studio單元測試小應用-測執行時間

【轉】Visual Studio單元測試小應用-測執行時間javascript

Visual Studio的單元測試會記錄每一個測試的執行時間,若是有幾個Method要測效能,之前我會用Stopwatch,最近我都改用單元測試來測,快又簡單。java

Visual Studio的單元測試會記錄每一個測試的執行時間,若是有幾個Method要測效能,之前我會用Stopwatch最近我都改用單元測試來測,快又簡單。spa

範例程式:有人說Catch不加Expection,因為不用匹配會比較快,我不相信,就來測測看。pwa

{
    for (int i = 0; i < 100000; i++)
    {
        try
        {
            var value = int.Parse("A");
        }
        catch
        {
        }
    }
}

public void Test2()
{
    for (int i = 0; i < 100000; i++)
    {
        try
        {
            var value = int.Parse("A");
        }
        catch (Exception)
        {
        }
    }            
}

image

好像真的快那麼一點點。3d

增長Duration欄位

在預設的設定下Test Results視窗是沒有Duration的欄位,必需本身增長。code

image

在Test Results視窗上按右鈕,選擇Add/Remove Columnsblog

image

選擇Duration欄位,這樣在Test Results就能夠很一目瞭然的看到測試結果。ip

相關文章
相關標籤/搜索