-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathIntroNuGet.cs
More file actions
66 lines (61 loc) · 1.79 KB
/
IntroNuGet.cs
File metadata and controls
66 lines (61 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.IO.Hashing;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
namespace BenchmarkDotNet.Samples
{
/// <summary>
/// Benchmarks between various versions of a NuGet package
/// </summary>
/// <remarks>
/// Only supported with CsProj toolchains.
/// </remarks>
[Config(typeof(Config))]
[UseLocalJobOnly]
public class IntroNuGet
{
// Setup your csproj like this:
/*
<PropertyGroup>
<!-- Use 8.0.0 as default package version if not specified -->
<SihVersion Condition="'$(SihVersion)' == ''">8.0.0</SciVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.IO.Hashing" Version="$(SihVersion)" />
</ItemGroup>
*/
// All versions of the package must be source-compatible with your benchmark code.
private class Config : ManualConfig
{
public Config()
{
string[] targetVersions = [
"8.0.0",
"9.0.0",
"10.0.0",
];
foreach (var version in targetVersions)
{
AddJob(Job.MediumRun
.WithMsBuildArguments($"/p:SihVersion={version}")
.WithId($"v{version}")
);
}
}
}
private static readonly byte[] values;
static IntroNuGet()
{
var rand = new Random(Seed: 0);
values = new byte[10_000];
rand.NextBytes(values);
}
[Benchmark]
public void XxHash3Benchmark()
{
var results = XxHash3.Hash(values);
}
}
}