在性能负载测试期间,秒表经过的毫秒数在少数情况下为0

时间:2019-01-10 18:44:59

标签: c# asp.net .net .net-core

在少数情况下,我们在负载测试期间记录了“ 0”毫秒,但在开发测试期间无法创建此问题。任何人都有 遇到相同的问题,并愿意知道是否有最佳实践     使用秒表。

private Stopwatch stopWatch = new Stopwatch();
[HttpGet]
[Route("/Test")]
public string TestStopWatch(bool throwExcetion)
{
    stopWatch.Start();

    try
    {
        Thread.Sleep(2 * 1000);
        if (throwExcetion == true) throw new Exception("exception thrown");
        return "Method executed successfully";
    }
    catch (Exception ex)
    {
        return "Method is thrown exception";
    }
    finally
    {
        stopWatch.Stop();
        Console.WriteLine($" Elapsed Time: {stopWatch.ElapsedMilliseconds.ToString()}");
        stopWatch.Reset();
    }
}

0 个答案:

没有答案