【问题标题】:BenchmarkDotNet, skip a benchmark on specific runtimeBenchmarkDotNet,跳过特定运行时的基准
【发布时间】:2019-12-20 08:41:20
【问题描述】:

(https://benchmarkdotnet.org/)

是否可以跳过特定运行时的单个基准测试部分?

例如,我想测试 4.7.2 和 Core 3.1 的几个功能, 但应该只在 Core31 上做替补

[Benchmark]
public void CoreOnly()
{
#if NETCOREAPP3_1
    //some stuff i only want to test with 3.1
#endif
}

[Benchmark]
public void General()
{
    //some stuff i want to test on all runtimes
}

这就是我到目前为止所做的。 有没有更好的办法?

【问题讨论】:

  • 如何将#if#endif 部分移到方法外以将其完全封装?
  • 那么它不会检测到 CoreOnly() 基准,并且只测试了 General。在我的版本中,CoreOnly() 被添加到 4.7.2-report 中,速度超快 XD。我希望 CoreOnly() 隐藏在结果报告中(不,我不想手动从报告中删除它;))

标签: c# benchmarkdotnet


【解决方案1】:

这在设计上是不可能的。

当运行以 XYZ 框架为目标的宿主进程时,BDN 正在使用反射来获取可用方法(基准)的列表。如果您使用 #if 定义,那么基准测试列表将因主机进程目标框架而异。

Performance repo 文档描述了如何在此处比较多个运行时性能: https://github.com/dotnet/performance/blob/master/docs/benchmarkdotnet.md#multiple-runtimes

主机进程需要是您要比较的运行时的最低通用 API 分母!

您可以在此处阅读有关测试多个运行时的更多信息: https://benchmarkdotnet.org/articles/configs/toolchains.html#multiple-frameworks-support

【讨论】:

    猜你喜欢
    • 2018-09-12
    • 1970-01-01
    • 2020-03-27
    • 2022-01-13
    • 1970-01-01
    • 2023-03-03
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多