From 86201b970998ad76c8a2665ec9af3b18302ffe24 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:50:38 +0500 Subject: [PATCH 01/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Classes\Customer.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\Classes\Customer.cs --- src/{Benchmark => Benchmark.Development}/Classes/Customer.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/Classes/Customer.cs (100%) diff --git a/src/Benchmark/Classes/Customer.cs b/src/Benchmark.Development/Classes/Customer.cs similarity index 100% rename from src/Benchmark/Classes/Customer.cs rename to src/Benchmark.Development/Classes/Customer.cs From 4f3428055169c616b60128f8bb97c11313e800b4 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:50:38 +0500 Subject: [PATCH 02/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Classes\Customer.cs --- src/Benchmark/Classes/Customer.cs | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Benchmark/Classes/Customer.cs diff --git a/src/Benchmark/Classes/Customer.cs b/src/Benchmark/Classes/Customer.cs new file mode 100644 index 00000000..5fac9cef --- /dev/null +++ b/src/Benchmark/Classes/Customer.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; + +namespace Benchmark.Classes +{ + public class Address + { + public int Id { get; set; } + public string Street { get; set; } + public string City { get; set; } + public string Country { get; set; } + } + + public class AddressDTO + { + public int Id { get; set; } + public string City { get; set; } + public string Country { get; set; } + } + + public class Customer + { + public int Id { get; set; } + public string Name { get; set; } + public decimal? Credit { get; set; } + public Address Address { get; set; } + public Address HomeAddress { get; set; } + public Address[] Addresses { get; set; } + public ICollection
WorkAddresses { get; set; } + } + + public class CustomerDTO + { + public int Id { get; set; } + public string Name { get; set; } + public Address Address { get; set; } + public AddressDTO HomeAddress { get; set; } + public AddressDTO[] Addresses { get; set; } + public List WorkAddresses { get; set; } + public string AddressCity { get; set; } + } +} From bd8c6dc0d63b7d79cc8df0c6c7d97a195efb24c6 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:51:19 +0500 Subject: [PATCH 03/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Classes\Foo.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\Classes\Foo.cs --- src/{Benchmark => Benchmark.Development}/Classes/Foo.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/Classes/Foo.cs (100%) diff --git a/src/Benchmark/Classes/Foo.cs b/src/Benchmark.Development/Classes/Foo.cs similarity index 100% rename from src/Benchmark/Classes/Foo.cs rename to src/Benchmark.Development/Classes/Foo.cs From 38efba5d361fe09cf2026c64018b5b185dfeb985 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:51:19 +0500 Subject: [PATCH 04/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Classes\Foo.cs --- src/Benchmark/Classes/Foo.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Benchmark/Classes/Foo.cs diff --git a/src/Benchmark/Classes/Foo.cs b/src/Benchmark/Classes/Foo.cs new file mode 100644 index 00000000..063541b8 --- /dev/null +++ b/src/Benchmark/Classes/Foo.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +namespace Benchmark.Classes +{ + public class Foo + { + public string Name { get; set; } + + public int Int32 { get; set; } + + public long Int64 { set; get; } + + public int? NullInt { get; set; } + + public float Floatn { get; set; } + + public double Doublen { get; set; } + + public DateTime DateTime { get; set; } + + public Foo Foo1 { get; set; } + + public IEnumerable Foos { get; set; } + + public Foo[] FooArr { get; set; } + + public int[] IntArr { get; set; } + + public IEnumerable Ints { get; set; } + } +} From ef0c17f3867218f7cded34baee5cfc6fd1351775 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:53:39 +0500 Subject: [PATCH 05/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\Config.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\Benchmarks\Config.cs --- src/{Benchmark => Benchmark.Development}/Benchmarks/Config.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/Benchmarks/Config.cs (100%) diff --git a/src/Benchmark/Benchmarks/Config.cs b/src/Benchmark.Development/Benchmarks/Config.cs similarity index 100% rename from src/Benchmark/Benchmarks/Config.cs rename to src/Benchmark.Development/Benchmarks/Config.cs From 80a981d935333e8ac4dded5f636736b0e023a6ec Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:53:39 +0500 Subject: [PATCH 06/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\Config.cs --- src/Benchmark/Benchmarks/Config.cs | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Benchmark/Benchmarks/Config.cs diff --git a/src/Benchmark/Benchmarks/Config.cs b/src/Benchmark/Benchmarks/Config.cs new file mode 100644 index 00000000..5779b353 --- /dev/null +++ b/src/Benchmark/Benchmarks/Config.cs @@ -0,0 +1,40 @@ +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Exporters; +using BenchmarkDotNet.Exporters.Csv; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Loggers; + +namespace Benchmark.Benchmarks +{ + public class Config : ManualConfig + { + public Config() + { + AddLogger(ConsoleLogger.Default); + + AddExporter(CsvExporter.Default); + AddExporter(MarkdownExporter.GitHub); + AddExporter(HtmlExporter.Default); + + AddDiagnoser(MemoryDiagnoser.Default); + AddColumn(TargetMethodColumn.Method); + + AddColumn(StatisticColumn.Mean); + AddColumn(StatisticColumn.StdDev); + AddColumn(StatisticColumn.Error); + + AddColumn(BaselineRatioColumn.RatioMean); + AddColumnProvider(DefaultColumnProviders.Metrics); + + AddJob(Job.ShortRun + .WithLaunchCount(1) + .WithWarmupCount(2) + .WithIterationCount(10) + ); + + Options |= ConfigOptions.JoinSummary; + } + } +} \ No newline at end of file From c08e5e9427e44fd66fd8879f661c258aa3ccd395 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:54:15 +0500 Subject: [PATCH 07/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\TestAll.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\Benchmarks\TestAll.cs --- src/{Benchmark => Benchmark.Development}/Benchmarks/TestAll.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/Benchmarks/TestAll.cs (100%) diff --git a/src/Benchmark/Benchmarks/TestAll.cs b/src/Benchmark.Development/Benchmarks/TestAll.cs similarity index 100% rename from src/Benchmark/Benchmarks/TestAll.cs rename to src/Benchmark.Development/Benchmarks/TestAll.cs From b2bbfca04ad40dfe2d11480387ee8c9616eb34e0 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:54:15 +0500 Subject: [PATCH 08/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\TestAll.cs --- src/Benchmark/Benchmarks/TestAll.cs | 111 ++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/Benchmark/Benchmarks/TestAll.cs diff --git a/src/Benchmark/Benchmarks/TestAll.cs b/src/Benchmark/Benchmarks/TestAll.cs new file mode 100644 index 00000000..40388f24 --- /dev/null +++ b/src/Benchmark/Benchmarks/TestAll.cs @@ -0,0 +1,111 @@ +using Benchmark.Classes; +using BenchmarkDotNet.Attributes; + +namespace Benchmark.Benchmarks +{ + public class TestAll + { + private Foo _fooInstance; + private Customer _customerInstance; + + [Params(100_000)]//, 1_000_000)] + public int Iterations { get; set; } + + [Benchmark(Description = "Mapster 7.2.0")] + public void MapsterTest() + { + TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + } + + [Benchmark(Description = "Mapster 7.2.0 (Roslyn)")] + public void RoslynTest() + { + TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + } + + [Benchmark(Description = "Mapster 7.2.0 (FEC)")] + public void FecTest() + { + TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + } + + [Benchmark(Description = "Mapster 7.2.0 (Codegen)")] + public void CodegenTest() + { + TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); + TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); + } + + [Benchmark(Description = "ExpressMapper 1.9.1")] + public void ExpressMapperTest() + { + TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); + TestAdaptHelper.TestExpressMapper(_customerInstance, Iterations); + } + + [Benchmark(Description = "AutoMapper 10.1.1")] + public void AutoMapperTest() + { + TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); + TestAdaptHelper.TestAutoMapper(_customerInstance, Iterations); + } + + [GlobalSetup(Target = nameof(MapsterTest))] + public void SetupMapster() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Default); + TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default); + } + + [GlobalSetup(Target = nameof(RoslynTest))] + public void SetupRoslyn() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); + TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Roslyn); + } + + [GlobalSetup(Target = nameof(FecTest))] + public void SetupFec() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); + TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); + } + + [GlobalSetup(Target = nameof(CodegenTest))] + public void SetupCodegen() + { + //_fooInstance = TestAdaptHelper.SetupFooInstance(); + //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); + //FooMapper.Map(_fooInstance); + //CustomerMapper.Map(_customerInstance); + } + + [GlobalSetup(Target = nameof(ExpressMapperTest))] + public void SetupExpressMapper() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureExpressMapper(_fooInstance); + TestAdaptHelper.ConfigureExpressMapper(_customerInstance); + } + + [GlobalSetup(Target = nameof(AutoMapperTest))] + public void SetupAutoMapper() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureAutoMapper(_fooInstance); + TestAdaptHelper.ConfigureAutoMapper(_customerInstance); + } + + } +} \ No newline at end of file From 7443373657fa6be41c265202065c475ba543aaa6 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:54:50 +0500 Subject: [PATCH 09/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\TestComplexTypes.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\Benchmarks\TestComplexTypes.cs --- .../Benchmarks/TestComplexTypes.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/Benchmarks/TestComplexTypes.cs (100%) diff --git a/src/Benchmark/Benchmarks/TestComplexTypes.cs b/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs similarity index 100% rename from src/Benchmark/Benchmarks/TestComplexTypes.cs rename to src/Benchmark.Development/Benchmarks/TestComplexTypes.cs From 191ce976b52c6b5465c939494e815ac6234c320c Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:54:50 +0500 Subject: [PATCH 10/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\TestComplexTypes.cs --- src/Benchmark/Benchmarks/TestComplexTypes.cs | 91 ++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/Benchmark/Benchmarks/TestComplexTypes.cs diff --git a/src/Benchmark/Benchmarks/TestComplexTypes.cs b/src/Benchmark/Benchmarks/TestComplexTypes.cs new file mode 100644 index 00000000..971f2e73 --- /dev/null +++ b/src/Benchmark/Benchmarks/TestComplexTypes.cs @@ -0,0 +1,91 @@ +using Benchmark.Classes; +using BenchmarkDotNet.Attributes; + +namespace Benchmark.Benchmarks +{ + public class TestComplexTypes + { + private Customer _customerInstance; + + [Params(1000, 10_000, 100_000, 1_000_000)] + public int Iterations { get; set; } + + [Benchmark] + public void MapsterTest() + { + TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + } + + [Benchmark(Description = "Mapster 6.0.0 (Roslyn)")] + public void RoslynTest() + { + TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + } + + [Benchmark(Description = "Mapster 6.0.0 (FEC)")] + public void FecTest() + { + TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + } + + [Benchmark] + public void CodegenTest() + { + TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); + } + + [Benchmark] + public void ExpressMapperTest() + { + TestAdaptHelper.TestExpressMapper(_customerInstance, Iterations); + } + + [Benchmark] + public void AutoMapperTest() + { + TestAdaptHelper.TestAutoMapper(_customerInstance, Iterations); + } + + [GlobalSetup(Target = nameof(MapsterTest))] + public void SetupMapster() + { + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default); + } + + [GlobalSetup(Target = nameof(RoslynTest))] + public void SetupRoslyn() + { + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Roslyn); + } + + [GlobalSetup(Target = nameof(FecTest))] + public void SetupFec() + { + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); + } + + [GlobalSetup(Target = nameof(CodegenTest))] + public void SetupCodegen() + { + //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); + //CustomerMapper.Map(_customerInstance); + } + + [GlobalSetup(Target = nameof(ExpressMapperTest))] + public void SetupExpressMapper() + { + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureExpressMapper(_customerInstance); + } + + [GlobalSetup(Target = nameof(AutoMapperTest))] + public void SetupAutoMapper() + { + _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + TestAdaptHelper.ConfigureAutoMapper(_customerInstance); + } + } +} \ No newline at end of file From 2b4ce196c7a119a903c3d30ee39148af93c5089c Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:56:08 +0500 Subject: [PATCH 11/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\TestSimpleTypes.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\Benchmarks\TestSimpleTypes.cs --- .../Benchmarks/TestSimpleTypes.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/Benchmarks/TestSimpleTypes.cs (100%) diff --git a/src/Benchmark/Benchmarks/TestSimpleTypes.cs b/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs similarity index 100% rename from src/Benchmark/Benchmarks/TestSimpleTypes.cs rename to src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs From 430fa728f0628e54df271f160aa0bf41646fe65a Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:56:08 +0500 Subject: [PATCH 12/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\Benchmarks\TestSimpleTypes.cs --- src/Benchmark/Benchmarks/TestSimpleTypes.cs | 92 +++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/Benchmark/Benchmarks/TestSimpleTypes.cs diff --git a/src/Benchmark/Benchmarks/TestSimpleTypes.cs b/src/Benchmark/Benchmarks/TestSimpleTypes.cs new file mode 100644 index 00000000..7c832a56 --- /dev/null +++ b/src/Benchmark/Benchmarks/TestSimpleTypes.cs @@ -0,0 +1,92 @@ +using Benchmark.Classes; +using BenchmarkDotNet.Attributes; + +namespace Benchmark.Benchmarks +{ + public class TestSimpleTypes + { + private Foo _fooInstance; + + [Params(1000, 10_000, 100_000, 1_000_000)] + public int Iterations { get; set; } + + [Benchmark] + public void MapsterTest() + { + TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + } + + [Benchmark(Description = "Mapster 6.0.0 (Roslyn)")] + public void RoslynTest() + { + TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + } + + [Benchmark(Description = "Mapster 6.0.0 (FEC)")] + public void FecTest() + { + TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + } + + [Benchmark] + public void CodegenTest() + { + TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); + } + + [Benchmark] + public void ExpressMapperTest() + { + TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); + } + + [Benchmark] + public void AutoMapperTest() + { + TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); + } + + + [GlobalSetup(Target = nameof(MapsterTest))] + public void SetupMapster() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Default); + } + + [GlobalSetup(Target = nameof(RoslynTest))] + public void SetupRoslyn() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); + } + + [GlobalSetup(Target = nameof(FecTest))] + public void SetupFec() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); + } + + [GlobalSetup(Target = nameof(CodegenTest))] + public void SetupCodegen() + { + //_fooInstance = TestAdaptHelper.SetupFooInstance(); + //FooMapper.Map(_fooInstance); + } + + [GlobalSetup(Target = nameof(ExpressMapperTest))] + public void SetupExpressMapper() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + TestAdaptHelper.ConfigureExpressMapper(_fooInstance); + } + + [GlobalSetup(Target = nameof(AutoMapperTest))] + public void SetupAutoMapper() + { + _fooInstance = TestAdaptHelper.SetupFooInstance(); + TestAdaptHelper.ConfigureAutoMapper(_fooInstance); + } + } +} \ No newline at end of file From 87dcfb40e66b9c337fb5b9c15493a8087c937704 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:58:42 +0500 Subject: [PATCH 13/16] --Duplicate C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\TestAdaptHelper.cs history into C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark.Development\TestAdaptHelper.cs --- src/{Benchmark => Benchmark.Development}/TestAdaptHelper.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Benchmark => Benchmark.Development}/TestAdaptHelper.cs (100%) diff --git a/src/Benchmark/TestAdaptHelper.cs b/src/Benchmark.Development/TestAdaptHelper.cs similarity index 100% rename from src/Benchmark/TestAdaptHelper.cs rename to src/Benchmark.Development/TestAdaptHelper.cs From 0b2604dddf538e8437cd3e4dadb7300e97933bb8 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 05:58:42 +0500 Subject: [PATCH 14/16] --Restore C:\Users\DocSv\source\repos\DocSvartz\Mapster\src\Benchmark\TestAdaptHelper.cs --- src/Benchmark/TestAdaptHelper.cs | 156 +++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/Benchmark/TestAdaptHelper.cs diff --git a/src/Benchmark/TestAdaptHelper.cs b/src/Benchmark/TestAdaptHelper.cs new file mode 100644 index 00000000..3d7db0eb --- /dev/null +++ b/src/Benchmark/TestAdaptHelper.cs @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using AutoMapper; +using Benchmark.Classes; +using FastExpressionCompiler; +using Mapster; + +namespace Benchmark +{ + public static class TestAdaptHelper + { + private static readonly IMapper _mapper = new Mapper(new MapperConfiguration(cfg => + { + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + })); + + public static Customer SetupCustomerInstance() + { + return new Customer + { + Address = new Address { City = "istanbul", Country = "turkey", Id = 1, Street = "istiklal cad." }, + HomeAddress = new Address { City = "istanbul", Country = "turkey", Id = 2, Street = "istiklal cad." }, + Id = 1, + Name = "Eduardo Najera", + Credit = 234.7m, + WorkAddresses = new List
+ { + new Address {City = "istanbul", Country = "turkey", Id = 5, Street = "istiklal cad."}, + new Address {City = "izmir", Country = "turkey", Id = 6, Street = "konak"} + }, + Addresses = new[] + { + new Address {City = "istanbul", Country = "turkey", Id = 3, Street = "istiklal cad."}, + new Address {City = "izmir", Country = "turkey", Id = 4, Street = "konak"} + } + }; + } + + public static Foo SetupFooInstance() + { + return new Foo + { + Name = "foo", + Int32 = 12, + Int64 = 123123, + NullInt = 16, + DateTime = DateTime.Now, + Doublen = 2312112, + Foo1 = new Foo { Name = "foo one" }, + Foos = new List + { + new Foo {Name = "j1", Int64 = 123, NullInt = 321}, + new Foo {Name = "j2", Int32 = 12345, NullInt = 54321}, + new Foo {Name = "j3", Int32 = 12345, NullInt = 54321} + }, + FooArr = new[] + { + new Foo {Name = "a1"}, + new Foo {Name = "a2"}, + new Foo {Name = "a3"} + }, + IntArr = new[] { 1, 2, 3, 4, 5 }, + Ints = new[] { 7, 8, 9 } + }; + } + + private static readonly Func _defaultCompiler = TypeAdapterConfig.GlobalSettings.Compiler; + + private static void SetupCompiler(MapsterCompilerType type) + { + TypeAdapterConfig.GlobalSettings.Compiler = type switch + { + MapsterCompilerType.Default => _defaultCompiler, + MapsterCompilerType.Roslyn => exp => exp.CompileWithDebugInfo(), + MapsterCompilerType.FEC => exp => exp.CompileFast(), + _ => throw new ArgumentOutOfRangeException(nameof(type)), + }; + } + public static void ConfigureMapster(Foo fooInstance, MapsterCompilerType type) + { + SetupCompiler(type); + TypeAdapterConfig.GlobalSettings.Compile(typeof(Foo), typeof(Foo)); //recompile + fooInstance.Adapt(); //exercise + } + public static void ConfigureExpressMapper(Foo fooInstance) + { + //ExpressMapper.Mapper.Map(fooInstance); //exercise + } + public static void ConfigureAutoMapper(Foo fooInstance) + { + _mapper.Map(fooInstance); //exercise + } + + public static void ConfigureMapster(Customer customerInstance, MapsterCompilerType type) + { + SetupCompiler(type); + TypeAdapterConfig.GlobalSettings.Compile(typeof(Customer), typeof(CustomerDTO)); //recompile + customerInstance.Adapt(); //exercise + } + public static void ConfigureExpressMapper(Customer customerInstance) + { + //ExpressMapper.Mapper.Map(customerInstance); //exercise + } + public static void ConfigureAutoMapper(Customer customerInstance) + { + _mapper.Map(customerInstance); //exercise + } + + public static void TestMapsterAdapter(TSrc item, int iterations) + where TSrc : class + where TDest : class, new() + { + Loop(item, get => get.Adapt(), iterations); + } + + public static void TestExpressMapper(TSrc item, int iterations) + where TSrc : class + where TDest : class, new() + { + //Loop(item, get => ExpressMapper.Mapper.Map(get), iterations); + } + + public static void TestAutoMapper(TSrc item, int iterations) + where TSrc : class + where TDest : class, new() + { + Loop(item, get => _mapper.Map(get), iterations); + } + + public static void TestCodeGen(Foo item, int iterations) + { + //Loop(item, get => FooMapper.Map(get), iterations); + } + + public static void TestCodeGen(Customer item, int iterations) + { + //Loop(item, get => CustomerMapper.Map(get), iterations); + } + + private static void Loop(T item, Action action, int iterations) + { + for (var i = 0; i < iterations; i++) action(item); + } + } + + public enum MapsterCompilerType + { + Default, + Roslyn, + FEC, + } +} \ No newline at end of file From 047bc78113023fc07a88769de6577774263cb1f9 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 08:05:59 +0500 Subject: [PATCH 15/16] add benchmark developers --- .../Benchmark.Development.csproj | 24 +++ .../Benchmark.Development.snk | Bin 0 -> 596 bytes .../Benchmarks/TestAll.cs | 140 +++++++++--------- .../Benchmarks/TestComplexTypes.cs | 26 ++-- .../Benchmarks/TestSimpleTypes.cs | 90 +++++------ .../Directory.Build.props | 24 +++ src/Benchmark.Development/Program.cs | 11 ++ src/Benchmark.Development/TestAdaptHelper.cs | 25 +--- src/Mapster.sln | 10 +- 9 files changed, 202 insertions(+), 148 deletions(-) create mode 100644 src/Benchmark.Development/Benchmark.Development.csproj create mode 100644 src/Benchmark.Development/Benchmark.Development.snk create mode 100644 src/Benchmark.Development/Directory.Build.props create mode 100644 src/Benchmark.Development/Program.cs diff --git a/src/Benchmark.Development/Benchmark.Development.csproj b/src/Benchmark.Development/Benchmark.Development.csproj new file mode 100644 index 00000000..18c5a1f8 --- /dev/null +++ b/src/Benchmark.Development/Benchmark.Development.csproj @@ -0,0 +1,24 @@ + + + + Exe + net9.0 + true + enable + enable + True + Benchmark.Development.snk + False + + + + + + + + + + + + + diff --git a/src/Benchmark.Development/Benchmark.Development.snk b/src/Benchmark.Development/Benchmark.Development.snk new file mode 100644 index 0000000000000000000000000000000000000000..beae8ece53cb310defad6c2729d3c6bfe93c88ff GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098mFb5}c)VvsS19hm9+)LYgiAma0ebK1!QT6HH9+X zkMNacZ@?@xo!u2jB@!jOn1BNA$gF z;PjWmQv`(2PTuY>9aMg587L7~RUYg7Bfne%@UMccxHqBlI2i3&GG`vw&!+kLS@dAH zcHe`z@w%C2eSz{7*-5dZqRp3XEBL_GlyJr15KzZq%JNZ;sG)6f+1P}*8F44MB}mn; zxHC5HbhH4T#ts7Yh_+O-)BfMepT%}BL;cCbH6%w^S*fPUruE)zv9%nS(b={?sq4ps zNIBD88ZFiv>LmMayAR&Z%DWG&^oGO77-yg?bi39l(o2Um<+uu#ScL19MuI|4_;dVs z34LbmS9I6sqTCTRL64DYGXn!LMdZ?ds%dOPuny(_customerInstance, Iterations); } - [Benchmark(Description = "Mapster 7.2.0 (Roslyn)")] - public void RoslynTest() - { - TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); - } + //[Benchmark(Description = "Mapster 7.2.0 (Roslyn)")] + //public void RoslynTest() + //{ + // TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + // TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + //} - [Benchmark(Description = "Mapster 7.2.0 (FEC)")] - public void FecTest() - { - TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); - } + //[Benchmark(Description = "Mapster 7.2.0 (FEC)")] + //public void FecTest() + //{ + // TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + // TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); + //} - [Benchmark(Description = "Mapster 7.2.0 (Codegen)")] - public void CodegenTest() - { - TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); - TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); - } + //[Benchmark(Description = "Mapster 7.2.0 (Codegen)")] + //public void CodegenTest() + //{ + // TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); + // TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); + //} - [Benchmark(Description = "ExpressMapper 1.9.1")] - public void ExpressMapperTest() - { - TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); - TestAdaptHelper.TestExpressMapper(_customerInstance, Iterations); - } + //[Benchmark(Description = "ExpressMapper 1.9.1")] + //public void ExpressMapperTest() + //{ + // TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); + // TestAdaptHelper.TestExpressMapper(_customerInstance, Iterations); + //} - [Benchmark(Description = "AutoMapper 10.1.1")] - public void AutoMapperTest() - { - TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); - TestAdaptHelper.TestAutoMapper(_customerInstance, Iterations); - } + //[Benchmark(Description = "AutoMapper 10.1.1")] + //public void AutoMapperTest() + //{ + // TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); + // TestAdaptHelper.TestAutoMapper(_customerInstance, Iterations); + //} [GlobalSetup(Target = nameof(MapsterTest))] public void SetupMapster() @@ -62,50 +62,50 @@ public void SetupMapster() TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default); } - [GlobalSetup(Target = nameof(RoslynTest))] - public void SetupRoslyn() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); - TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Roslyn); - } + //[GlobalSetup(Target = nameof(RoslynTest))] + //public void SetupRoslyn() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + // TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); + // TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Roslyn); + //} - [GlobalSetup(Target = nameof(FecTest))] - public void SetupFec() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); - TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); - } + //[GlobalSetup(Target = nameof(FecTest))] + //public void SetupFec() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + // TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); + // TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); + //} - [GlobalSetup(Target = nameof(CodegenTest))] - public void SetupCodegen() - { - //_fooInstance = TestAdaptHelper.SetupFooInstance(); - //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); - //FooMapper.Map(_fooInstance); - //CustomerMapper.Map(_customerInstance); - } + //[GlobalSetup(Target = nameof(CodegenTest))] + //public void SetupCodegen() + //{ + // //_fooInstance = TestAdaptHelper.SetupFooInstance(); + // //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); + // //FooMapper.Map(_fooInstance); + // //CustomerMapper.Map(_customerInstance); + //} - [GlobalSetup(Target = nameof(ExpressMapperTest))] - public void SetupExpressMapper() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureExpressMapper(_fooInstance); - TestAdaptHelper.ConfigureExpressMapper(_customerInstance); - } + //[GlobalSetup(Target = nameof(ExpressMapperTest))] + //public void SetupExpressMapper() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + // TestAdaptHelper.ConfigureExpressMapper(_fooInstance); + // TestAdaptHelper.ConfigureExpressMapper(_customerInstance); + //} - [GlobalSetup(Target = nameof(AutoMapperTest))] - public void SetupAutoMapper() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureAutoMapper(_fooInstance); - TestAdaptHelper.ConfigureAutoMapper(_customerInstance); - } + //[GlobalSetup(Target = nameof(AutoMapperTest))] + //public void SetupAutoMapper() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + // TestAdaptHelper.ConfigureAutoMapper(_fooInstance); + // TestAdaptHelper.ConfigureAutoMapper(_customerInstance); + //} } } \ No newline at end of file diff --git a/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs b/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs index 971f2e73..44250741 100644 --- a/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs +++ b/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs @@ -28,11 +28,11 @@ public void FecTest() TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); } - [Benchmark] - public void CodegenTest() - { - TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); - } + //[Benchmark] + //public void CodegenTest() + //{ + // TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); + //} [Benchmark] public void ExpressMapperTest() @@ -67,12 +67,12 @@ public void SetupFec() TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); } - [GlobalSetup(Target = nameof(CodegenTest))] + /* [GlobalSetup(Target = nameof(CodegenTest))] public void SetupCodegen() { //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); //CustomerMapper.Map(_customerInstance); - } + }*/ [GlobalSetup(Target = nameof(ExpressMapperTest))] public void SetupExpressMapper() @@ -81,11 +81,11 @@ public void SetupExpressMapper() TestAdaptHelper.ConfigureExpressMapper(_customerInstance); } - [GlobalSetup(Target = nameof(AutoMapperTest))] - public void SetupAutoMapper() - { - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureAutoMapper(_customerInstance); - } + //[GlobalSetup(Target = nameof(AutoMapperTest))] + //public void SetupAutoMapper() + //{ + // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); + // TestAdaptHelper.ConfigureAutoMapper(_customerInstance); + //} } } \ No newline at end of file diff --git a/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs b/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs index 7c832a56..9a86538f 100644 --- a/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs +++ b/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs @@ -16,35 +16,35 @@ public void MapsterTest() TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); } - [Benchmark(Description = "Mapster 6.0.0 (Roslyn)")] + [Benchmark(Description = "Mapster 7.4.0 (Roslyn)")] public void RoslynTest() { TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); } - [Benchmark(Description = "Mapster 6.0.0 (FEC)")] - public void FecTest() - { - TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - } + //[Benchmark(Description = "Mapster 6.0.0 (FEC)")] + //public void FecTest() + //{ + // TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); + //} - [Benchmark] - public void CodegenTest() - { - TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); - } + //[Benchmark] + //public void CodegenTest() + //{ + // TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); + //} - [Benchmark] - public void ExpressMapperTest() - { - TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); - } + //[Benchmark] + //public void ExpressMapperTest() + //{ + // TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); + //} - [Benchmark] - public void AutoMapperTest() - { - TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); - } + //[Benchmark] + //public void AutoMapperTest() + //{ + // TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); + //} [GlobalSetup(Target = nameof(MapsterTest))] @@ -61,32 +61,32 @@ public void SetupRoslyn() TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); } - [GlobalSetup(Target = nameof(FecTest))] - public void SetupFec() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); - } + //[GlobalSetup(Target = nameof(FecTest))] + //public void SetupFec() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); + //} - [GlobalSetup(Target = nameof(CodegenTest))] - public void SetupCodegen() - { - //_fooInstance = TestAdaptHelper.SetupFooInstance(); - //FooMapper.Map(_fooInstance); - } + //[GlobalSetup(Target = nameof(CodegenTest))] + //public void SetupCodegen() + //{ + // //_fooInstance = TestAdaptHelper.SetupFooInstance(); + // //FooMapper.Map(_fooInstance); + //} - [GlobalSetup(Target = nameof(ExpressMapperTest))] - public void SetupExpressMapper() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - TestAdaptHelper.ConfigureExpressMapper(_fooInstance); - } + //[GlobalSetup(Target = nameof(ExpressMapperTest))] + //public void SetupExpressMapper() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // TestAdaptHelper.ConfigureExpressMapper(_fooInstance); + //} - [GlobalSetup(Target = nameof(AutoMapperTest))] - public void SetupAutoMapper() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - TestAdaptHelper.ConfigureAutoMapper(_fooInstance); - } + //[GlobalSetup(Target = nameof(AutoMapperTest))] + //public void SetupAutoMapper() + //{ + // _fooInstance = TestAdaptHelper.SetupFooInstance(); + // TestAdaptHelper.ConfigureAutoMapper(_fooInstance); + //} } } \ No newline at end of file diff --git a/src/Benchmark.Development/Directory.Build.props b/src/Benchmark.Development/Directory.Build.props new file mode 100644 index 00000000..cb200b6d --- /dev/null +++ b/src/Benchmark.Development/Directory.Build.props @@ -0,0 +1,24 @@ + + + + false + + + + chaowlert;eric_swann;andrerav + Copyright (c) $([System.DateTime]::Now.ToString(`yyyy`)) Chaowlert Chaisrichalermpol, Eric Swann, Andreas Ravnestad + false + https://github.com/MapsterMapper/Mapster + https://github.com/MapsterMapper/Mapster + + logo.png + https://cloud.githubusercontent.com/assets/5763993/26522718/d16f3e42-4330-11e7-9b78-f8c7402624e7.png + MIT + false + true + Mapper;AutoMapper;Fast;Mapping + icon.png + false + 10 + + \ No newline at end of file diff --git a/src/Benchmark.Development/Program.cs b/src/Benchmark.Development/Program.cs new file mode 100644 index 00000000..32e641ed --- /dev/null +++ b/src/Benchmark.Development/Program.cs @@ -0,0 +1,11 @@ +using Benchmark.Benchmarks; +using BenchmarkDotNet.Running; + +var switcher = new BenchmarkSwitcher(new[] + { + typeof(TestSimpleTypes), + typeof(TestComplexTypes), + typeof(TestAll), + }); + +switcher.Run(args, new Config()); diff --git a/src/Benchmark.Development/TestAdaptHelper.cs b/src/Benchmark.Development/TestAdaptHelper.cs index 3d7db0eb..0c6222c2 100644 --- a/src/Benchmark.Development/TestAdaptHelper.cs +++ b/src/Benchmark.Development/TestAdaptHelper.cs @@ -1,23 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using AutoMapper; -using Benchmark.Classes; -using FastExpressionCompiler; +using Benchmark.Classes; using Mapster; +using System.Linq.Expressions; namespace Benchmark { public static class TestAdaptHelper { - private static readonly IMapper _mapper = new Mapper(new MapperConfiguration(cfg => - { - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); - })); - + public static Customer SetupCustomerInstance() { return new Customer @@ -76,7 +65,7 @@ private static void SetupCompiler(MapsterCompilerType type) { MapsterCompilerType.Default => _defaultCompiler, MapsterCompilerType.Roslyn => exp => exp.CompileWithDebugInfo(), - MapsterCompilerType.FEC => exp => exp.CompileFast(), + // MapsterCompilerType.FEC => exp => exp.CompileFast(), _ => throw new ArgumentOutOfRangeException(nameof(type)), }; } @@ -92,7 +81,7 @@ public static void ConfigureExpressMapper(Foo fooInstance) } public static void ConfigureAutoMapper(Foo fooInstance) { - _mapper.Map(fooInstance); //exercise + //_mapper.Map(fooInstance); //exercise } public static void ConfigureMapster(Customer customerInstance, MapsterCompilerType type) @@ -107,7 +96,7 @@ public static void ConfigureExpressMapper(Customer customerInstance) } public static void ConfigureAutoMapper(Customer customerInstance) { - _mapper.Map(customerInstance); //exercise + //_mapper.Map(customerInstance); //exercise } public static void TestMapsterAdapter(TSrc item, int iterations) @@ -128,7 +117,7 @@ public static void TestAutoMapper(TSrc item, int iterations) where TSrc : class where TDest : class, new() { - Loop(item, get => _mapper.Map(get), iterations); + // Loop(item, get => _mapper.Map(get), iterations); } public static void TestCodeGen(Foo item, int iterations) diff --git a/src/Mapster.sln b/src/Mapster.sln index befd616f..f55ef5d1 100644 --- a/src/Mapster.sln +++ b/src/Mapster.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.32014.148 +# Visual Studio Version 18 +VisualStudioVersion = 18.1.11304.174 d18.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A5580F9D-0F5F-4224-980F-7824536A627D}" ProjectSection(SolutionItems) = preProject @@ -63,6 +63,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TemplateTest", "TemplateTes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mapster.Tool.Tests", "Mapster.Tool.Tests\Mapster.Tool.Tests.csproj", "{E64E9CEB-8FB2-4012-BBA8-4C2B99FD54C1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark.Development", "Benchmark.Development\Benchmark.Development.csproj", "{5F29425E-DFC6-48C2-945A-FC5D91260C07}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -161,6 +163,10 @@ Global {E64E9CEB-8FB2-4012-BBA8-4C2B99FD54C1}.Debug|Any CPU.Build.0 = Debug|Any CPU {E64E9CEB-8FB2-4012-BBA8-4C2B99FD54C1}.Release|Any CPU.ActiveCfg = Release|Any CPU {E64E9CEB-8FB2-4012-BBA8-4C2B99FD54C1}.Release|Any CPU.Build.0 = Release|Any CPU + {5F29425E-DFC6-48C2-945A-FC5D91260C07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F29425E-DFC6-48C2-945A-FC5D91260C07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F29425E-DFC6-48C2-945A-FC5D91260C07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F29425E-DFC6-48C2-945A-FC5D91260C07}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From e9203940d291bded55012ba036dd75860caadfc6 Mon Sep 17 00:00:00 2001 From: DocSvartz Date: Sun, 14 Dec 2025 10:14:06 +0500 Subject: [PATCH 16/16] fix benchmark config --- .../Benchmark.Development.csproj | 6 +- .../Benchmarks/Config.cs | 24 ++++-- .../Benchmarks/TestAll.cs | 83 +------------------ .../Benchmarks/TestComplexTypes.cs | 67 +-------------- .../Benchmarks/TestSimpleTypes.cs | 66 --------------- .../Directory.Build.props | 8 +- src/Benchmark.Development/TestAdaptHelper.cs | 46 +--------- 7 files changed, 29 insertions(+), 271 deletions(-) diff --git a/src/Benchmark.Development/Benchmark.Development.csproj b/src/Benchmark.Development/Benchmark.Development.csproj index 18c5a1f8..572bdf29 100644 --- a/src/Benchmark.Development/Benchmark.Development.csproj +++ b/src/Benchmark.Development/Benchmark.Development.csproj @@ -2,13 +2,15 @@ Exe - net9.0 + net10.0 true enable enable True Benchmark.Development.snk False + 7.4.0 + 12.0 @@ -18,7 +20,7 @@ - + diff --git a/src/Benchmark.Development/Benchmarks/Config.cs b/src/Benchmark.Development/Benchmarks/Config.cs index 5779b353..554581ab 100644 --- a/src/Benchmark.Development/Benchmarks/Config.cs +++ b/src/Benchmark.Development/Benchmarks/Config.cs @@ -5,6 +5,7 @@ using BenchmarkDotNet.Exporters.Csv; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Loggers; +using Perfolizer.Models; namespace Benchmark.Benchmarks { @@ -21,18 +22,31 @@ public Config() AddDiagnoser(MemoryDiagnoser.Default); AddColumn(TargetMethodColumn.Method); + AddColumn(JobCharacteristicColumn.AllColumns); + AddColumnProvider(DefaultColumnProviders.Params); AddColumn(StatisticColumn.Mean); + AddColumn(StatisticColumn.StdDev); AddColumn(StatisticColumn.Error); AddColumn(BaselineRatioColumn.RatioMean); AddColumnProvider(DefaultColumnProviders.Metrics); - AddJob(Job.ShortRun - .WithLaunchCount(1) - .WithWarmupCount(2) - .WithIterationCount(10) - ); + string[] targetVersions = [ + "7.4.0", + "9.0.0-pre01", + ]; + + foreach (var version in targetVersions) + { + AddJob(Job.ShortRun + .WithLaunchCount(1) + .WithWarmupCount(2) + .WithIterationCount(10) + .WithMsBuildArguments($"/p:SciVersion={version}") + .WithId($"v{version}") + ); + } Options |= ConfigOptions.JoinSummary; } diff --git a/src/Benchmark.Development/Benchmarks/TestAll.cs b/src/Benchmark.Development/Benchmarks/TestAll.cs index 842a9a4f..b3e28a76 100644 --- a/src/Benchmark.Development/Benchmarks/TestAll.cs +++ b/src/Benchmark.Development/Benchmarks/TestAll.cs @@ -11,48 +11,13 @@ public class TestAll [Params(100_000)]//, 1_000_000)] public int Iterations { get; set; } - [Benchmark(Description = "Mapster 7.2.0")] + [Benchmark] public void MapsterTest() { TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); } - //[Benchmark(Description = "Mapster 7.2.0 (Roslyn)")] - //public void RoslynTest() - //{ - // TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - // TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); - //} - - //[Benchmark(Description = "Mapster 7.2.0 (FEC)")] - //public void FecTest() - //{ - // TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - // TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); - //} - - //[Benchmark(Description = "Mapster 7.2.0 (Codegen)")] - //public void CodegenTest() - //{ - // TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); - // TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); - //} - - //[Benchmark(Description = "ExpressMapper 1.9.1")] - //public void ExpressMapperTest() - //{ - // TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); - // TestAdaptHelper.TestExpressMapper(_customerInstance, Iterations); - //} - - //[Benchmark(Description = "AutoMapper 10.1.1")] - //public void AutoMapperTest() - //{ - // TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); - // TestAdaptHelper.TestAutoMapper(_customerInstance, Iterations); - //} - [GlobalSetup(Target = nameof(MapsterTest))] public void SetupMapster() { @@ -61,51 +26,5 @@ public void SetupMapster() TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Default); TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default); } - - //[GlobalSetup(Target = nameof(RoslynTest))] - //public void SetupRoslyn() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - // TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); - // TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Roslyn); - //} - - //[GlobalSetup(Target = nameof(FecTest))] - //public void SetupFec() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - // TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); - // TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); - //} - - //[GlobalSetup(Target = nameof(CodegenTest))] - //public void SetupCodegen() - //{ - // //_fooInstance = TestAdaptHelper.SetupFooInstance(); - // //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); - // //FooMapper.Map(_fooInstance); - // //CustomerMapper.Map(_customerInstance); - //} - - //[GlobalSetup(Target = nameof(ExpressMapperTest))] - //public void SetupExpressMapper() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - // TestAdaptHelper.ConfigureExpressMapper(_fooInstance); - // TestAdaptHelper.ConfigureExpressMapper(_customerInstance); - //} - - //[GlobalSetup(Target = nameof(AutoMapperTest))] - //public void SetupAutoMapper() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - // TestAdaptHelper.ConfigureAutoMapper(_fooInstance); - // TestAdaptHelper.ConfigureAutoMapper(_customerInstance); - //} - } } \ No newline at end of file diff --git a/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs b/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs index 44250741..62d7a764 100644 --- a/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs +++ b/src/Benchmark.Development/Benchmarks/TestComplexTypes.cs @@ -15,77 +15,12 @@ public void MapsterTest() { TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); } - - [Benchmark(Description = "Mapster 6.0.0 (Roslyn)")] - public void RoslynTest() - { - TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); - } - - [Benchmark(Description = "Mapster 6.0.0 (FEC)")] - public void FecTest() - { - TestAdaptHelper.TestMapsterAdapter(_customerInstance, Iterations); - } - - //[Benchmark] - //public void CodegenTest() - //{ - // TestAdaptHelper.TestCodeGen(_customerInstance, Iterations); - //} - - [Benchmark] - public void ExpressMapperTest() - { - TestAdaptHelper.TestExpressMapper(_customerInstance, Iterations); - } - - [Benchmark] - public void AutoMapperTest() - { - TestAdaptHelper.TestAutoMapper(_customerInstance, Iterations); - } - + [GlobalSetup(Target = nameof(MapsterTest))] public void SetupMapster() { _customerInstance = TestAdaptHelper.SetupCustomerInstance(); TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Default); } - - [GlobalSetup(Target = nameof(RoslynTest))] - public void SetupRoslyn() - { - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.Roslyn); - } - - [GlobalSetup(Target = nameof(FecTest))] - public void SetupFec() - { - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureMapster(_customerInstance, MapsterCompilerType.FEC); - } - - /* [GlobalSetup(Target = nameof(CodegenTest))] - public void SetupCodegen() - { - //_customerInstance = TestAdaptHelper.SetupCustomerInstance(); - //CustomerMapper.Map(_customerInstance); - }*/ - - [GlobalSetup(Target = nameof(ExpressMapperTest))] - public void SetupExpressMapper() - { - _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - TestAdaptHelper.ConfigureExpressMapper(_customerInstance); - } - - //[GlobalSetup(Target = nameof(AutoMapperTest))] - //public void SetupAutoMapper() - //{ - // _customerInstance = TestAdaptHelper.SetupCustomerInstance(); - // TestAdaptHelper.ConfigureAutoMapper(_customerInstance); - //} } } \ No newline at end of file diff --git a/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs b/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs index 9a86538f..8678a8ec 100644 --- a/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs +++ b/src/Benchmark.Development/Benchmarks/TestSimpleTypes.cs @@ -16,77 +16,11 @@ public void MapsterTest() TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); } - [Benchmark(Description = "Mapster 7.4.0 (Roslyn)")] - public void RoslynTest() - { - TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - } - - //[Benchmark(Description = "Mapster 6.0.0 (FEC)")] - //public void FecTest() - //{ - // TestAdaptHelper.TestMapsterAdapter(_fooInstance, Iterations); - //} - - //[Benchmark] - //public void CodegenTest() - //{ - // TestAdaptHelper.TestCodeGen(_fooInstance, Iterations); - //} - - //[Benchmark] - //public void ExpressMapperTest() - //{ - // TestAdaptHelper.TestExpressMapper(_fooInstance, Iterations); - //} - - //[Benchmark] - //public void AutoMapperTest() - //{ - // TestAdaptHelper.TestAutoMapper(_fooInstance, Iterations); - //} - - [GlobalSetup(Target = nameof(MapsterTest))] public void SetupMapster() { _fooInstance = TestAdaptHelper.SetupFooInstance(); TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Default); } - - [GlobalSetup(Target = nameof(RoslynTest))] - public void SetupRoslyn() - { - _fooInstance = TestAdaptHelper.SetupFooInstance(); - TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.Roslyn); - } - - //[GlobalSetup(Target = nameof(FecTest))] - //public void SetupFec() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // TestAdaptHelper.ConfigureMapster(_fooInstance, MapsterCompilerType.FEC); - //} - - //[GlobalSetup(Target = nameof(CodegenTest))] - //public void SetupCodegen() - //{ - // //_fooInstance = TestAdaptHelper.SetupFooInstance(); - // //FooMapper.Map(_fooInstance); - //} - - //[GlobalSetup(Target = nameof(ExpressMapperTest))] - //public void SetupExpressMapper() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // TestAdaptHelper.ConfigureExpressMapper(_fooInstance); - //} - - //[GlobalSetup(Target = nameof(AutoMapperTest))] - //public void SetupAutoMapper() - //{ - // _fooInstance = TestAdaptHelper.SetupFooInstance(); - // TestAdaptHelper.ConfigureAutoMapper(_fooInstance); - //} } } \ No newline at end of file diff --git a/src/Benchmark.Development/Directory.Build.props b/src/Benchmark.Development/Directory.Build.props index cb200b6d..8c415f63 100644 --- a/src/Benchmark.Development/Directory.Build.props +++ b/src/Benchmark.Development/Directory.Build.props @@ -8,17 +8,11 @@ chaowlert;eric_swann;andrerav Copyright (c) $([System.DateTime]::Now.ToString(`yyyy`)) Chaowlert Chaisrichalermpol, Eric Swann, Andreas Ravnestad false - https://github.com/MapsterMapper/Mapster - https://github.com/MapsterMapper/Mapster - logo.png - https://cloud.githubusercontent.com/assets/5763993/26522718/d16f3e42-4330-11e7-9b78-f8c7402624e7.png MIT false true - Mapper;AutoMapper;Fast;Mapping - icon.png false - 10 + 12 \ No newline at end of file diff --git a/src/Benchmark.Development/TestAdaptHelper.cs b/src/Benchmark.Development/TestAdaptHelper.cs index 0c6222c2..c6e06739 100644 --- a/src/Benchmark.Development/TestAdaptHelper.cs +++ b/src/Benchmark.Development/TestAdaptHelper.cs @@ -64,7 +64,7 @@ private static void SetupCompiler(MapsterCompilerType type) TypeAdapterConfig.GlobalSettings.Compiler = type switch { MapsterCompilerType.Default => _defaultCompiler, - MapsterCompilerType.Roslyn => exp => exp.CompileWithDebugInfo(), + // MapsterCompilerType.Roslyn => exp => exp.CompileWithDebugInfo(), // MapsterCompilerType.FEC => exp => exp.CompileFast(), _ => throw new ArgumentOutOfRangeException(nameof(type)), }; @@ -75,30 +75,14 @@ public static void ConfigureMapster(Foo fooInstance, MapsterCompilerType type) TypeAdapterConfig.GlobalSettings.Compile(typeof(Foo), typeof(Foo)); //recompile fooInstance.Adapt(); //exercise } - public static void ConfigureExpressMapper(Foo fooInstance) - { - //ExpressMapper.Mapper.Map(fooInstance); //exercise - } - public static void ConfigureAutoMapper(Foo fooInstance) - { - //_mapper.Map(fooInstance); //exercise - } - + public static void ConfigureMapster(Customer customerInstance, MapsterCompilerType type) { SetupCompiler(type); TypeAdapterConfig.GlobalSettings.Compile(typeof(Customer), typeof(CustomerDTO)); //recompile customerInstance.Adapt(); //exercise } - public static void ConfigureExpressMapper(Customer customerInstance) - { - //ExpressMapper.Mapper.Map(customerInstance); //exercise - } - public static void ConfigureAutoMapper(Customer customerInstance) - { - //_mapper.Map(customerInstance); //exercise - } - + public static void TestMapsterAdapter(TSrc item, int iterations) where TSrc : class where TDest : class, new() @@ -106,30 +90,6 @@ public static void TestMapsterAdapter(TSrc item, int iterations) Loop(item, get => get.Adapt(), iterations); } - public static void TestExpressMapper(TSrc item, int iterations) - where TSrc : class - where TDest : class, new() - { - //Loop(item, get => ExpressMapper.Mapper.Map(get), iterations); - } - - public static void TestAutoMapper(TSrc item, int iterations) - where TSrc : class - where TDest : class, new() - { - // Loop(item, get => _mapper.Map(get), iterations); - } - - public static void TestCodeGen(Foo item, int iterations) - { - //Loop(item, get => FooMapper.Map(get), iterations); - } - - public static void TestCodeGen(Customer item, int iterations) - { - //Loop(item, get => CustomerMapper.Map(get), iterations); - } - private static void Loop(T item, Action action, int iterations) { for (var i = 0; i < iterations; i++) action(item);