Skip to content

Commit bf15fa4

Browse files
authored
chore: Add Benchmark.Development
Add benchmark to development
2 parents db4bfae + b167649 commit bf15fa4

File tree

12 files changed

+375
-0
lines changed

12 files changed

+375
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<CopyLocalLockFileAssemblies Condition=" '$(Configuration)'=='Debug' ">true</CopyLocalLockFileAssemblies>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<SignAssembly>True</SignAssembly>
10+
<AssemblyOriginatorKeyFile>Benchmark.Development.snk</AssemblyOriginatorKeyFile>
11+
<DelaySign>False</DelaySign>
12+
<SciVersion Condition="'$(SciVersion)' == ''">7.4.0</SciVersion>
13+
<LangVersion>12.0</LangVersion>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<Folder Include="Benchmarks\" />
18+
<Folder Include="Classes\" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
23+
<PackageReference Include="Mapster" Version="$(SciVersion)" />
24+
</ItemGroup>
25+
26+
</Project>
596 Bytes
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using BenchmarkDotNet.Columns;
2+
using BenchmarkDotNet.Configs;
3+
using BenchmarkDotNet.Diagnosers;
4+
using BenchmarkDotNet.Exporters;
5+
using BenchmarkDotNet.Exporters.Csv;
6+
using BenchmarkDotNet.Jobs;
7+
using BenchmarkDotNet.Loggers;
8+
using Perfolizer.Models;
9+
10+
namespace Benchmark.Benchmarks
11+
{
12+
public class Config : ManualConfig
13+
{
14+
public Config()
15+
{
16+
AddLogger(ConsoleLogger.Default);
17+
18+
AddExporter(CsvExporter.Default);
19+
AddExporter(MarkdownExporter.GitHub);
20+
AddExporter(HtmlExporter.Default);
21+
22+
AddDiagnoser(MemoryDiagnoser.Default);
23+
AddColumn(TargetMethodColumn.Method);
24+
25+
AddColumn(JobCharacteristicColumn.AllColumns);
26+
AddColumnProvider(DefaultColumnProviders.Params);
27+
AddColumn(StatisticColumn.Mean);
28+
29+
AddColumn(StatisticColumn.StdDev);
30+
AddColumn(StatisticColumn.Error);
31+
32+
AddColumn(BaselineRatioColumn.RatioMean);
33+
AddColumnProvider(DefaultColumnProviders.Metrics);
34+
35+
string[] targetVersions = [
36+
"7.4.0",
37+
"9.0.0-pre01",
38+
];
39+
40+
foreach (var version in targetVersions)
41+
{
42+
AddJob(Job.ShortRun
43+
.WithLaunchCount(1)
44+
.WithWarmupCount(2)
45+
.WithIterationCount(10)
46+
.WithMsBuildArguments($"/p:SciVersion={version}")
47+
.WithId($"v{version}")
48+
);
49+
}
50+
51+
Options |= ConfigOptions.JoinSummary;
52+
}
53+
}
54+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Benchmark.Classes;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace Benchmark.Benchmarks
5+
{
6+
public class TestAll
7+
{
8+
private Foo _fooInstance;
9+
private Customer _customerInstance;
10+
11+
[Params(100_000)]//, 1_000_000)]
12+
public int Iterations { get; set; }
13+
14+
[Benchmark]
15+
public void MapsterTest()
16+
{
17+
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
18+
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
19+
}
20+
21+
[GlobalSetup(Target = nameof(MapsterTest))]
22+
public void SetupMapster()
23+
{
24+
_fooInstance = TestAdaptHelper.SetupFooInstance();
25+
_customerInstance = TestAdaptHelper.SetupCustomerInstance();
26+
TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Default);
27+
TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default);
28+
}
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Benchmark.Classes;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace Benchmark.Benchmarks
5+
{
6+
public class TestComplexTypes
7+
{
8+
private Customer _customerInstance;
9+
10+
[Params(1000, 10_000, 100_000, 1_000_000)]
11+
public int Iterations { get; set; }
12+
13+
[Benchmark]
14+
public void MapsterTest()
15+
{
16+
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
17+
}
18+
19+
[GlobalSetup(Target = nameof(MapsterTest))]
20+
public void SetupMapster()
21+
{
22+
_customerInstance = TestAdaptHelper.SetupCustomerInstance();
23+
TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default);
24+
}
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Benchmark.Classes;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace Benchmark.Benchmarks
5+
{
6+
public class TestSimpleTypes
7+
{
8+
private Foo _fooInstance;
9+
10+
[Params(1000, 10_000, 100_000, 1_000_000)]
11+
public int Iterations { get; set; }
12+
13+
[Benchmark]
14+
public void MapsterTest()
15+
{
16+
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
17+
}
18+
19+
[GlobalSetup(Target = nameof(MapsterTest))]
20+
public void SetupMapster()
21+
{
22+
_fooInstance = TestAdaptHelper.SetupFooInstance();
23+
TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Default);
24+
}
25+
}
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Collections.Generic;
2+
3+
namespace Benchmark.Classes
4+
{
5+
public class Address
6+
{
7+
public int Id { get; set; }
8+
public string Street { get; set; }
9+
public string City { get; set; }
10+
public string Country { get; set; }
11+
}
12+
13+
public class AddressDTO
14+
{
15+
public int Id { get; set; }
16+
public string City { get; set; }
17+
public string Country { get; set; }
18+
}
19+
20+
public class Customer
21+
{
22+
public int Id { get; set; }
23+
public string Name { get; set; }
24+
public decimal? Credit { get; set; }
25+
public Address Address { get; set; }
26+
public Address HomeAddress { get; set; }
27+
public Address[] Addresses { get; set; }
28+
public ICollection<Address> WorkAddresses { get; set; }
29+
}
30+
31+
public class CustomerDTO
32+
{
33+
public int Id { get; set; }
34+
public string Name { get; set; }
35+
public Address Address { get; set; }
36+
public AddressDTO HomeAddress { get; set; }
37+
public AddressDTO[] Addresses { get; set; }
38+
public List<AddressDTO> WorkAddresses { get; set; }
39+
public string AddressCity { get; set; }
40+
}
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Benchmark.Classes
5+
{
6+
public class Foo
7+
{
8+
public string Name { get; set; }
9+
10+
public int Int32 { get; set; }
11+
12+
public long Int64 { set; get; }
13+
14+
public int? NullInt { get; set; }
15+
16+
public float Floatn { get; set; }
17+
18+
public double Doublen { get; set; }
19+
20+
public DateTime DateTime { get; set; }
21+
22+
public Foo Foo1 { get; set; }
23+
24+
public IEnumerable<Foo> Foos { get; set; }
25+
26+
public Foo[] FooArr { get; set; }
27+
28+
public int[] IntArr { get; set; }
29+
30+
public IEnumerable<int> Ints { get; set; }
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project>
2+
<PropertyGroup>
3+
<!-- Properties related to build/pack -->
4+
<IsPackable>false</IsPackable>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<!-- Metadata -->
8+
<Authors>chaowlert;eric_swann;andrerav</Authors>
9+
<Copyright>Copyright (c) $([System.DateTime]::Now.ToString(`yyyy`)) Chaowlert Chaisrichalermpol, Eric Swann, Andreas Ravnestad</Copyright>
10+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
11+
<PackageReleaseNotes></PackageReleaseNotes>
12+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13+
<SignAssembly>false</SignAssembly>
14+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
15+
<IsPackable>false</IsPackable>
16+
<LangVersion>12</LangVersion>
17+
</PropertyGroup>
18+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Benchmark.Benchmarks;
2+
using BenchmarkDotNet.Running;
3+
4+
var switcher = new BenchmarkSwitcher(new[]
5+
{
6+
typeof(TestSimpleTypes),
7+
typeof(TestComplexTypes),
8+
typeof(TestAll),
9+
});
10+
11+
switcher.Run(args, new Config());

0 commit comments

Comments
 (0)