小编Vai*_*wis的帖子

我们如何在 C# 中的 BenchmarkDotNet 的 [Arguments] 标签中传递动态参数?

我正在尝试使用参数对方法进行基准测试。

[Benchmark]
public void ViewPlan(int x)
{
//code here
}
Run Code Online (Sandbox Code Playgroud)

在使用 [Benchmark] 注释执行代码时,出现错误“基准方法 ViewPlan 的签名不正确。方法不应有任何参数”。所以我也尝试向该方法添加 [Arguments] 注释。参考链接: https: //benchmarkdotnet.org/articles/samples/IntroArguments.html

[Benchmark]
[Arguments]
public void ViewPlan(int x)
{
//code here
}
Run Code Online (Sandbox Code Playgroud)

在此 [Arguments] 中,我们还需要指定方法的参数值。但是,x 的值是在调用该功能时动态设置的。有没有办法在 [Arguments] 中动态传递参数值?我们还可以对静态方法进行基准测试吗?如果可以,那么如何进行基准测试?

c# performance-testing benchmarkdotnet

3
推荐指数
1
解决办法
2873
查看次数

标签 统计

benchmarkdotnet ×1

c# ×1

performance-testing ×1