C#中的基准测试方法调用 [英] Benchmarking method calls in C#

查看:100
本文介绍了C#中的基准测试方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来对C#中的方法调用进行基准测试.

I'm looking for a way to benchmark method calls in C#.

我已经为大学分配编写了数据结构,只是想出了一种优化方法,但是在所有情况下都会增加一点开销,同时将O(n)调用转换为O (1).

I have coded a data structure for university assignment, and just came up with a way to optimize a bit, but in a way that would add a bit of overhead in all situations, while turning a O(n) call into O(1) in some.

现在,我想针对测试数据运行两个版本,以查看是否值得实施优化.我知道在Ruby中,您可以将代码包装到Benchmark块中,并输出在控制台中执行该块所需的时间-是否有类似的代码可用于C#?

Now I want to run both versions against the test data to see if it's worth implementing the optimization. I know that in Ruby, you could wrap the code in a Benchmark block and have it output the time needed to execute the block in console - is there something like that available for C#?

推荐答案

您可以使用内置的 Stopwatch类到提供了一组可用于准确测量经过时间的方法和属性".如果您正在寻找手动方式.不过,不确定自动.

You could use the inbuilt Stopwatch class to "Provides a set of methods and properties that you can use to accurately measure elapsed time." if you are looking for a manual way to do it. Not sure on automated though.

这篇关于C#中的基准测试方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆