c# - BenchmarkDotNet,跳过特定运行时的基准
问题描述
( 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
}
这就是我到目前为止所做的。有没有更好的办法?
解决方案
这在设计上是不可能的。
当运行以 XYZ 框架为目标的宿主进程时,BDN 使用反射来获取可用方法(基准)的列表。如果您使用的是#if
定义,那么每个主机进程目标框架的基准测试列表都会有所不同。
性能 repo 文档描述了如何在此处比较多个运行时性能: https ://github.com/dotnet/performance/blob/master/docs/benchmarkdotnet.md#multiple-runtimes
主机进程必须是您要比较的运行时的最低通用 API 分母!
您可以在此处阅读有关测试多个运行时的更多信息: https ://benchmarkdotnet.org/articles/configs/toolchains.html#multiple-frameworks-support
推荐阅读
- python - 使用 os.path.join 在错误位置创建日志文件
- c++ - 尽管一切似乎都是正确的,VSCode 无法识别 g++?
- c# - 单击后动态创建的按钮消失
- reactjs - react-ultimate-pagination 如何设置 bootstrap 3 主题
- angular - 如何在轮播中为移动(小)设备使用不同的(小)图像?
- mysql - 无法通过 mysqlworkbench 连接到数据库服务器
- google-analytics - GA 自定义报告中未显示维度
- java - Quartz StdSchedulerFactory() 实例化在 Java 中挂起
- sql - 没有重复行的左连接 1 到 1 连接。使一个表中的每一行只连接到另一个表中的一行
- r - 将单列数据框转换为多列