我正在尝试使用 BenchmarkDotNet 为库准备性能回归测试。这要求我将相同的测试与旧(稳定)版本的库进行比较。现在,可以选择为作业提供不同版本的 NuGet 包。似乎没有一个选项可以代替引用不同的程序集。
我尝试过自定义构建配置:
<ItemGroup Condition="'$(Configuration)' == 'Baseline'">
<Reference Include="MyAssembly">
<HintPath>lib\baseline\MyAssembly.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' != 'Baseline'">
<Reference Include="MyAssembly">
<HintPath>lib\current\MyAssembly.dll</HintPath>
</Reference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
但是当尝试通过 BenchmarkDotNet 使用这些配置时
public static void Main(string[] args) {
var summary = BenchmarkRunner.Run(typeof(Program).Assembly,
DefaultConfig.Instance
.With(Job.Default.WithCustomBuildConfiguration("Baseline"))
.With(Job.Default.WithCustomBuildConfiguration("Current")));
}
Run Code Online (Sandbox Code Playgroud)
我收到构建错误,表明该程序集根本没有被引用。BenchmarkDotNet 还有助于清除它创建的任何临时工件,因此我什至无法查看生成的项目文件来弄清楚它的外观。
这里唯一的解决方法是将库包装在 NuGet 包中吗?或者在(对于这种情况看似稀疏的)文档中是否有我忽略的东西?
这个问题似乎与我遇到的构建错误隐约相关。
我能够得到类似的工作,这可能也适合你。就我而言,我想从基准项目的同一构建中引用 NuGet 和本地项目。
添加 和 后PackageReference,ProjectReference我(手动)将 添加Aliases到ProjectReference:
<ItemGroup>
<ProjectReference Include="..\src\Combinatorics\Combinatorics.csproj" Aliases="localbuild" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
dll 名称确实需要不同(因为两个 dll 最终都位于输出目录中)。因此,我更改了引用项目的 dll 名称(但仅在本地构建时而不是在进行持续集成构建时):
<PropertyGroup>
<AssemblyName Condition="'$(CI)'!='true'">local.Combinatorics</AssemblyName>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
然后我可以在同一个应用程序中使用extern alias和using使用这两个程序集:
extern alias localbuild;
using NugetCombinatorics = Combinatorics.Collections;
using LocalCombinatorics = localbuild::Combinatorics.Collections;
...
[BenchmarkCategory("Enumerate"), Benchmark(Baseline = true)]
public void EnumerateOld()
{
var permutations = new NugetCombinatorics.Permutations<int>(_source);
foreach (var p in permutations)
;
}
[BenchmarkCategory("Enumerate"), Benchmark]
public void EnumerateNew()
{
var permutations = new LocalCombinatorics.Permutations<int>(_source);
foreach (var p in permutations)
;
}
Run Code Online (Sandbox Code Playgroud)
重复的代码并不理想,我有点滥用类别而不是使用正确的运行,但它完成了工作。
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |