开放/结束计划的通用基准

时间:2017-04-20 19:46:37

标签: c# .net process benchmarking

我正在尝试创建一个通用的C#方法,可以对应用程序的打开和关闭进行基准测试,以比较测试系统中的这种性能(出于安全原因,我们的环境中的程序会干扰应用程序启动,我们希望自动测试其影响的方法)。这就是我目前为我的测试人员所做的事情:

public class ApplicationBenchmarker
{
    public string ApplicationName { get; private set; }
    public string ApplicationPath { get; private set; }

    public List<long> msOpenTimes { get; private set; } = new List<long>();

    public ApplicationBenchmarker(string applicationName, string applicationPath)
    {
        ApplicationName = applicationName;
        ApplicationPath = applicationPath;
    }

    public void Test()
    {
        Console.WriteLine("Application " + ApplicationName + " starting...");


        Stopwatch watch = new Stopwatch();
        watch.Start();
        Process process = Process.Start(ApplicationPath);
        process.WaitForInputIdle();
        process.CloseMainWindow();
        process.WaitForExit();
        watch.Stop();
        Console.WriteLine("Application " + ApplicationName + " exited.");
        msOpenTimes.Add(watch.ElapsedMilliseconds);
    }
}

在某些应用程序中对此进行测试,我得到了这种行为:

  • Notepad.exe - 代码似乎按预期工作,打开程序,然后关闭它,等待关闭记录时间。
  • IE.exe - 代码打开IE,但从不关闭IE。然而,它认为它确实关闭了,并且当IE仍处于打开状态时停止秒表。
  • EXCEL.EXE(Office 365,当前分支) - 代码打开Excel,但从不关闭它。代码挂起等待它关闭。

有没有更好的方法可以重新创建开启/关闭时间基准的一般行为?

0 个答案:

没有答案
相关问题