-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump .editorconfig & use file scoped namespaces
- Loading branch information
1 parent
d134fef
commit add335b
Showing
181 changed files
with
17,574 additions
and
17,753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 64 additions & 65 deletions
129
Benchmarks/Boxed.Mapping.Benchmark/MapArrayBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,80 @@ | ||
namespace Boxed.Mapping.Benchmark | ||
namespace Boxed.Mapping.Benchmark; | ||
|
||
using System; | ||
using System.Globalization; | ||
using AutoMapper; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using Boxed.Mapping.Benchmark.Mapping; | ||
using Boxed.Mapping.Benchmark.Models; | ||
|
||
[KeepBenchmarkFiles] | ||
[MemoryDiagnoser] | ||
[MinColumn] | ||
[MaxColumn] | ||
[HtmlExporter] | ||
[CsvMeasurementsExporter] | ||
[RPlotExporter] | ||
[SimpleJob(RuntimeMoniker.Net60)] | ||
[SimpleJob(RuntimeMoniker.Net50)] | ||
[SimpleJob(RuntimeMoniker.NetCoreApp30)] | ||
[SimpleJob(RuntimeMoniker.Net472)] | ||
public class MapArrayBenchmark | ||
{ | ||
using System; | ||
using System.Globalization; | ||
using AutoMapper; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using Boxed.Mapping.Benchmark.Mapping; | ||
using Boxed.Mapping.Benchmark.Models; | ||
private readonly IMapper automapper; | ||
private readonly IMapper<MapFrom, MapTo> boilerplateMapper; | ||
private readonly Random random; | ||
private MapFrom[] mapFrom = default!; | ||
|
||
[KeepBenchmarkFiles] | ||
[MemoryDiagnoser] | ||
[MinColumn] | ||
[MaxColumn] | ||
[HtmlExporter] | ||
[CsvMeasurementsExporter] | ||
[RPlotExporter] | ||
[SimpleJob(RuntimeMoniker.Net60)] | ||
[SimpleJob(RuntimeMoniker.Net50)] | ||
[SimpleJob(RuntimeMoniker.NetCoreApp30)] | ||
[SimpleJob(RuntimeMoniker.Net472)] | ||
public class MapArrayBenchmark | ||
public MapArrayBenchmark() | ||
{ | ||
private readonly IMapper automapper; | ||
private readonly IMapper<MapFrom, MapTo> boilerplateMapper; | ||
private readonly Random random; | ||
private MapFrom[] mapFrom = default!; | ||
|
||
public MapArrayBenchmark() | ||
{ | ||
this.automapper = AutomapperConfiguration.CreateMapper(); | ||
this.boilerplateMapper = new BoxedMapper(); | ||
this.random = new Random(); | ||
} | ||
this.automapper = AutomapperConfiguration.CreateMapper(); | ||
this.boilerplateMapper = new BoxedMapper(); | ||
this.random = new Random(); | ||
} | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
this.mapFrom = new MapFrom[100]; | ||
for (var i = 0; i < this.mapFrom.Length; ++i) | ||
{ | ||
this.mapFrom = new MapFrom[100]; | ||
for (var i = 0; i < this.mapFrom.Length; ++i) | ||
this.mapFrom[i] = new MapFrom() | ||
{ | ||
this.mapFrom[i] = new MapFrom() | ||
{ | ||
#pragma warning disable CA5394 // Do not use insecure randomness | ||
BooleanFrom = this.random.NextDouble() > 0.5D, | ||
DateTimeOffsetFrom = DateTimeOffset.UtcNow, | ||
IntegerFrom = this.random.Next(), | ||
LongFrom = this.random.Next(), | ||
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture), | ||
BooleanFrom = this.random.NextDouble() > 0.5D, | ||
DateTimeOffsetFrom = DateTimeOffset.UtcNow, | ||
IntegerFrom = this.random.Next(), | ||
LongFrom = this.random.Next(), | ||
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture), | ||
#pragma warning restore CA5394 // Do not use insecure randomness | ||
}; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public MapTo[] Baseline() | ||
[Benchmark(Baseline = true)] | ||
public MapTo[] Baseline() | ||
{ | ||
var destination = new MapTo[this.mapFrom.Length]; | ||
for (var i = 0; i < this.mapFrom.Length; ++i) | ||
{ | ||
var destination = new MapTo[this.mapFrom.Length]; | ||
for (var i = 0; i < this.mapFrom.Length; ++i) | ||
var item = this.mapFrom[i]; | ||
destination[i] = new MapTo() | ||
{ | ||
var item = this.mapFrom[i]; | ||
destination[i] = new MapTo() | ||
{ | ||
BooleanTo = item.BooleanFrom, | ||
DateTimeOffsetTo = item.DateTimeOffsetFrom, | ||
IntegerTo = item.IntegerFrom, | ||
LongTo = item.LongFrom, | ||
StringTo = item.StringFrom, | ||
}; | ||
} | ||
|
||
return destination; | ||
BooleanTo = item.BooleanFrom, | ||
DateTimeOffsetTo = item.DateTimeOffsetFrom, | ||
IntegerTo = item.IntegerFrom, | ||
LongTo = item.LongFrom, | ||
StringTo = item.StringFrom, | ||
}; | ||
} | ||
|
||
[Benchmark] | ||
public MapTo[] BoxedMapper() => this.boilerplateMapper.MapArray(this.mapFrom); | ||
|
||
[Benchmark] | ||
public MapTo[] Automapper() => this.automapper.Map<MapTo[]>(this.mapFrom); | ||
return destination; | ||
} | ||
|
||
[Benchmark] | ||
public MapTo[] BoxedMapper() => this.boilerplateMapper.MapArray(this.mapFrom); | ||
|
||
[Benchmark] | ||
public MapTo[] Automapper() => this.automapper.Map<MapTo[]>(this.mapFrom); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,82 @@ | ||
namespace Boxed.Mapping.Benchmark | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using AutoMapper; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using Boxed.Mapping.Benchmark.Mapping; | ||
using Boxed.Mapping.Benchmark.Models; | ||
namespace Boxed.Mapping.Benchmark; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using AutoMapper; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Jobs; | ||
using Boxed.Mapping.Benchmark.Mapping; | ||
using Boxed.Mapping.Benchmark.Models; | ||
|
||
#pragma warning disable CA1002 // Do not expose generic lists | ||
[KeepBenchmarkFiles] | ||
[MemoryDiagnoser] | ||
[MinColumn] | ||
[MaxColumn] | ||
[HtmlExporter] | ||
[CsvMeasurementsExporter] | ||
[RPlotExporter] | ||
[SimpleJob(RuntimeMoniker.Net60)] | ||
[SimpleJob(RuntimeMoniker.Net50)] | ||
[SimpleJob(RuntimeMoniker.NetCoreApp30)] | ||
[SimpleJob(RuntimeMoniker.Net472)] | ||
public class MapListBenchmark | ||
{ | ||
private readonly IMapper automapper; | ||
private readonly IMapper<MapFrom, MapTo> boilerplateMapper; | ||
private readonly Random random; | ||
private List<MapFrom> mapFrom = default!; | ||
[KeepBenchmarkFiles] | ||
[MemoryDiagnoser] | ||
[MinColumn] | ||
[MaxColumn] | ||
[HtmlExporter] | ||
[CsvMeasurementsExporter] | ||
[RPlotExporter] | ||
[SimpleJob(RuntimeMoniker.Net60)] | ||
[SimpleJob(RuntimeMoniker.Net50)] | ||
[SimpleJob(RuntimeMoniker.NetCoreApp30)] | ||
[SimpleJob(RuntimeMoniker.Net472)] | ||
public class MapListBenchmark | ||
{ | ||
private readonly IMapper automapper; | ||
private readonly IMapper<MapFrom, MapTo> boilerplateMapper; | ||
private readonly Random random; | ||
private List<MapFrom> mapFrom = default!; | ||
|
||
public MapListBenchmark() | ||
{ | ||
this.automapper = AutomapperConfiguration.CreateMapper(); | ||
this.boilerplateMapper = new BoxedMapper(); | ||
this.random = new Random(); | ||
} | ||
public MapListBenchmark() | ||
{ | ||
this.automapper = AutomapperConfiguration.CreateMapper(); | ||
this.boilerplateMapper = new BoxedMapper(); | ||
this.random = new Random(); | ||
} | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
this.mapFrom = new List<MapFrom>(); | ||
for (var i = 0; i < 100; ++i) | ||
{ | ||
this.mapFrom = new List<MapFrom>(); | ||
for (var i = 0; i < 100; ++i) | ||
{ | ||
this.mapFrom.Add( | ||
new MapFrom() | ||
{ | ||
this.mapFrom.Add( | ||
new MapFrom() | ||
{ | ||
#pragma warning disable CA5394 // Do not use insecure randomness | ||
BooleanFrom = this.random.NextDouble() > 0.5D, | ||
DateTimeOffsetFrom = DateTimeOffset.UtcNow, | ||
IntegerFrom = this.random.Next(), | ||
LongFrom = this.random.Next(), | ||
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture), | ||
DateTimeOffsetFrom = DateTimeOffset.UtcNow, | ||
IntegerFrom = this.random.Next(), | ||
LongFrom = this.random.Next(), | ||
StringFrom = this.random.Next().ToString(CultureInfo.InvariantCulture), | ||
#pragma warning restore CA5394 // Do not use insecure randomness | ||
}); | ||
} | ||
} | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public List<MapTo> Baseline() | ||
[Benchmark(Baseline = true)] | ||
public List<MapTo> Baseline() | ||
{ | ||
var destination = new List<MapTo>(this.mapFrom.Count); | ||
foreach (var item in this.mapFrom) | ||
{ | ||
var destination = new List<MapTo>(this.mapFrom.Count); | ||
foreach (var item in this.mapFrom) | ||
destination.Add(new MapTo() | ||
{ | ||
destination.Add(new MapTo() | ||
{ | ||
BooleanTo = item.BooleanFrom, | ||
DateTimeOffsetTo = item.DateTimeOffsetFrom, | ||
IntegerTo = item.IntegerFrom, | ||
LongTo = item.LongFrom, | ||
StringTo = item.StringFrom, | ||
}); | ||
} | ||
|
||
return destination; | ||
BooleanTo = item.BooleanFrom, | ||
DateTimeOffsetTo = item.DateTimeOffsetFrom, | ||
IntegerTo = item.IntegerFrom, | ||
LongTo = item.LongFrom, | ||
StringTo = item.StringFrom, | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public List<MapTo> BoxedMapper() => this.boilerplateMapper.MapList(this.mapFrom); | ||
|
||
[Benchmark] | ||
public List<MapTo> Automapper() => this.automapper.Map<List<MapTo>>(this.mapFrom); | ||
return destination; | ||
} | ||
#pragma warning restore CA1002 // Do not expose generic lists | ||
|
||
[Benchmark] | ||
public List<MapTo> BoxedMapper() => this.boilerplateMapper.MapList(this.mapFrom); | ||
|
||
[Benchmark] | ||
public List<MapTo> Automapper() => this.automapper.Map<List<MapTo>>(this.mapFrom); | ||
} |
Oops, something went wrong.