-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChampionChallengerEnumerableMapping.cs
62 lines (51 loc) · 2.07 KB
/
ChampionChallengerEnumerableMapping.cs
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
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using AutoMapper;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Jobs;
namespace Initialize.Benchmarks;
[SimpleJob(runStrategy: RunStrategy.Throughput, launchCount: 1, invocationCount: 1, iterationCount:10,
runtimeMoniker: RuntimeMoniker.Net70)]
[MemoryDiagnoser]
[HideColumns(Column.StdDev, Column.Median, Column.Error, Column.RatioSD)]
public class ChampionChallengerEnumerableMapping
{
private AutoMapper.Mapper _autoMapper;
private List<Test> _testObjects;
private IEnumerable<Test> _testEnumerable;
public ChampionChallengerEnumerableMapping()
{
//Initialize mapper
var config = new MapperConfiguration(cfg =>
cfg.CreateMap<Test, Test2>());
this._autoMapper = new AutoMapper.Mapper(config);
//Initialize mapper
Mapper<Test, Test2>.Map(new Test());
}
[Params(100, 1_000, 10_000, 100_000, 1_000_000)]
public int Iterations { get; set; }
[IterationSetup]
public void Setup()
{
this._testEnumerable = Enumerable.Range(0, this.Iterations)
.Select(r => new Test() { PropString = r.ToString(), Prop = r });
this._testObjects = this._testEnumerable.ToList();
}
[Benchmark(Description = "AutoMapper")]
public void AutoMapperEnumerable()
{
var result = this._autoMapper.Map<IEnumerable<Test>>(this._testEnumerable);
// if ((result.TryGetNonEnumeratedCount(out var cnt) && cnt != Iterations) || result.Count() != Iterations) throw new Exception($"{result.Count()} and {Iterations}not equal");
}
[Benchmark(Description = "Initialize")]
public void MapperEnumerable()
{
var result = Mapper<Test, Test2>.Map(this._testEnumerable);
//if ((result.TryGetNonEnumeratedCount(out var cnt) && cnt != Iterations) || result.Count() != Iterations) throw new Exception($"{result.Count()} and {Iterations}not equal");
}
}