如何为.Net应用程序编写性能测试?

发布于 2024-08-25 05:07:05 字数 97 浏览 1 评论 0原文

如何为.Net应用程序编写性能测试? nUnit 或任何其他测试框架是否为此提供了框架?

编辑:我必须衡量 WCF 服务的性能。

How to write Performance Test for .Net application? Does nUnit or any other Testing framework provides framework for this?

Edit: I have to measure performance of WCF Service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蒗幽 2024-09-01 05:07:05

如果您对方法和算法的相对性能感兴趣,可以在 NUnit 测试中使用 System.Diagnostic.StopWatch 类来编写有关某些方法需要多长时间的断言。

在下面的简单示例中,primes 类是使用 [SetUp] 方法(未显示)实例化的,因为我感兴趣的是generatePrimes 方法花费了多长时间,而不是我的类的实例化,并且我正在编写一个断言该方法应该花费不到 5 秒的时间。这不是一个非常具有挑战性的断言,但希望可以作为如何做到这一点的示例。

    [Test]
    public void checkGeneratePrimesUpToTenMillion()
    {
        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        timer.Start();
        long[] primeArray = primes.generatePrimes(10000000);
        timer.Stop();
        Assert.AreEqual(664579, primeArray.Length, "Should be 664,579 primes below ten million");
        int elapsedSeconds = timer.Elapsed.Seconds;
        Console.Write("Time in seconds to generate primes up to ten million: " + elapsedSeconds);
        bool ExecutionTimeLessThanFiveSeconds = (elapsedSeconds < 5);
        Assert.IsTrue(ExecutionTimeLessThanFiveSeconds, "Should take less than five seconds");
    }

If you are interested in relative performance of methods and algorithms, you can use the System.Diagnostic.StopWatch class in your NUnit tests to write assertions about how long certain methods take.

In the simple example below, the primes class is instantiated with a [SetUp] method (not shown), as I'm interested in how long the generatePrimes method is taking, not the instantiation of my class, and I'm writing an assertion that this method should take less than 5 seconds. This isn't a very challenging assertion, but hopefully serves as an example of how you could do this.

    [Test]
    public void checkGeneratePrimesUpToTenMillion()
    {
        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        timer.Start();
        long[] primeArray = primes.generatePrimes(10000000);
        timer.Stop();
        Assert.AreEqual(664579, primeArray.Length, "Should be 664,579 primes below ten million");
        int elapsedSeconds = timer.Elapsed.Seconds;
        Console.Write("Time in seconds to generate primes up to ten million: " + elapsedSeconds);
        bool ExecutionTimeLessThanFiveSeconds = (elapsedSeconds < 5);
        Assert.IsTrue(ExecutionTimeLessThanFiveSeconds, "Should take less than five seconds");
    }
长发绾君心 2024-09-01 05:07:05

我发现 NTime 看起来很适合编写性能测试。

http://www.codeproject.com/kb/dotnet/NTime.aspx

I came across NTime which looks cool for writing performance Tests.

http://www.codeproject.com/kb/dotnet/NTime.aspx

假面具 2024-09-01 05:07:05

NUnit 为您提供了一个单元测试框架:即在离散的“单元”中测试您的代码,以便您可以了解新的更改何时破坏了现有代码,或者您已经提供了一定级别的代码覆盖率。但它本身不提供性能测试。

为此,您将需要另一种类型的工具。如果您有网络应用程序,您可能想看看 The Grinder 或其他可以在这里找到的应用程序:

http ://www.opensourcetesting.org/performance.php

NUnit provides you with a framework for unit testing: i.e. testing your code in discrete "units" so that you can, amongst other things, be aware when new changes break existing code, or that you have provided a certain level of code coverage. But it does not provide performance testing per se.

For that, you will need another type of tool. If you have a webapp, you might like to take a look at The Grinder or others to be found here:

http://www.opensourcetesting.org/performance.php

满栀 2024-09-01 05:07:05

VS Team System内置了性能测试模块。如果你有许可证的话值得探索。

VS Team System has built in performance testing modules. Worth exploring if u have licence for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文