From 0d6b314fcea1175bd9234f67cedf4a94c82888b2 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Sat, 30 Dec 2023 16:21:26 +0300 Subject: [PATCH 01/11] add nextorm --- .../Benchmarks.EntityFrameworkCore.cs | 4 +++- benchmarks/Dapper.Tests.Performance/Config.cs | 3 ++- .../Dapper.Tests.Performance.csproj | 16 ++++++++++++++-- benchmarks/Dapper.Tests.Performance/Program.cs | 16 ++++++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs index 2c8b811b2..5fb68cc49 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.ComponentModel; +using System.Data.SqlClient; using System.Linq; namespace Dapper.Tests.Performance @@ -19,7 +20,8 @@ public class EFCoreBenchmarks : BenchmarkBase public void Setup() { BaseSetup(); - Context = new EFCoreContext(ConnectionString); + var connBuilder = new SqlConnectionStringBuilder(ConnectionString) { TrustServerCertificate = true }; + Context = new EFCoreContext(connBuilder.ConnectionString); } [Benchmark(Description = "First")] diff --git a/benchmarks/Dapper.Tests.Performance/Config.cs b/benchmarks/Dapper.Tests.Performance/Config.cs index b25eb3b82..2fcb41138 100644 --- a/benchmarks/Dapper.Tests.Performance/Config.cs +++ b/benchmarks/Dapper.Tests.Performance/Config.cs @@ -37,8 +37,9 @@ public Config() .WithLaunchCount(1) .WithWarmupCount(2) .WithUnrollFactor(Iterations) - .WithIterationCount(10) + .WithIterationCount(20) ); + // AddJob(Job.Default); Orderer = new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest); Options |= ConfigOptions.JoinSummary; } diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 10ad41cff..58f032b46 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -3,7 +3,7 @@ Dapper.Tests.Performance Dapper Core Performance Suite Exe - net462;net5.0 + net462;net5.0;net8.0 false $(NoWarn);IDE0063;IDE0034;IDE0059;IDE0060 @@ -46,9 +46,21 @@ + - + + + + + + + + + + + + diff --git a/benchmarks/Dapper.Tests.Performance/Program.cs b/benchmarks/Dapper.Tests.Performance/Program.cs index 1e102cf87..e6e91c10a 100644 --- a/benchmarks/Dapper.Tests.Performance/Program.cs +++ b/benchmarks/Dapper.Tests.Performance/Program.cs @@ -44,8 +44,20 @@ public static void Main(string[] args) } else { - WriteLine("Iterations: " + Config.Iterations); - new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); + // var d = new DapperBenchmarks(); + // d.Setup(); + // for (var i = 0; i < 10; i++) + // d.QueryFirstOrDefault(); +#if NET8_0_OR_GREATER + var norm = new NextormBenchmarks(); + norm.Setup(false); + for(var i=0;i<100;i++) + norm.QueryBufferedCompiled(); +#endif + // Console.WriteLine("Press any key to exit"); + // Console.ReadKey(); + // WriteLine("Iterations: " + Config.Iterations); + // new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); } } From 54cf189749db3b184d6960b5dd086bd3cdcddc7c Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Sat, 30 Dec 2023 16:21:26 +0300 Subject: [PATCH 02/11] add nextorm --- .../Benchmarks.EntityFrameworkCore.cs | 4 +- .../Benchmarks.Nextorm.cs | 121 ++++++++++++++++++ benchmarks/Dapper.Tests.Performance/Config.cs | 3 +- .../Dapper.Tests.Performance.csproj | 16 ++- .../Dapper.Tests.Performance/Program.cs | 16 ++- 5 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs index 2c8b811b2..5fb68cc49 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.ComponentModel; +using System.Data.SqlClient; using System.Linq; namespace Dapper.Tests.Performance @@ -19,7 +20,8 @@ public class EFCoreBenchmarks : BenchmarkBase public void Setup() { BaseSetup(); - Context = new EFCoreContext(ConnectionString); + var connBuilder = new SqlConnectionStringBuilder(ConnectionString) { TrustServerCertificate = true }; + Context = new EFCoreContext(connBuilder.ConnectionString); } [Benchmark(Description = "First")] diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs new file mode 100644 index 000000000..0c8389657 --- /dev/null +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs @@ -0,0 +1,121 @@ +using System; +using System.ComponentModel; +using System.Linq; +using BenchmarkDotNet.Attributes; +using DevExpress.Data.Access; +using System.Data.SqlClient; +using Microsoft.Extensions.Logging; +using nextorm.core; +using nextorm.sqlserver; + +namespace Dapper.Tests.Performance; + +[Description("Nextorm")] +public class NextormBenchmarks : BenchmarkBase +{ + private NextormRepository _repository; + private QueryCommand _getPostByIdCompiled; + private QueryCommand _getPostById; + private QueryCommand _queryBufferedCompiled; + private QueryCommand _queryUnbufferedCompiled; + + // private QueryCommand _getPosts; + // private QueryCommand _getPostsStream; + + [GlobalSetup] + public void GlobalSetup() => Setup(false); + public void Setup(bool withLogging) + { + BaseSetup(); + var builder = new DbContextBuilder(); + builder.UseSqlServer(_connection); + if (withLogging) + { + var logFactory = LoggerFactory.Create(config => config.AddConsole().SetMinimumLevel(LogLevel.Debug)); + builder.UseLoggerFactory(logFactory); + builder.LogSensetiveData(true); + } + + _repository = new NextormRepository(builder); + + var c = _repository.Posts.Where(it => it.Id == NORM.Param(0)); + _queryBufferedCompiled = c.ToCommand().Compile(); + _queryUnbufferedCompiled = c.ToCommand().Compile(false); + _getPostByIdCompiled = c.FirstOrFirstOrDefaultCommand().Compile(); + _getPostById = _repository.Posts.Where(it => it.Id == NORM.Param(0)).FirstOrFirstOrDefaultCommand(); + // _getPosts = _repository.Posts.Limit(QueryLimit).ToCommand().Compile(true); + // _getPostsStream = _repository.Posts.Limit(QueryLimit).ToCommand().Compile(false); + //Console.WriteLine("Setup complete"); + } + [Benchmark(Description = "First")] + public Post First() + { + Step(); + return _repository.Posts.Where(it => it.Id == i).FirstOrDefault(); + } + + [Benchmark(Description = "First with param")] + public Post FirstParam() + { + Step(); + return _getPostById.FirstOrDefault(i); + } + + [Benchmark(Description = "First compiled")] + public Post FirstCompiled() + { + Step(); + return _getPostByIdCompiled.FirstOrDefault(i); + } + [Benchmark(Description = "Query (compiled buffered)")] + public Post QueryBufferedCompiled() + { + Step(); + return _queryBufferedCompiled.ToList(i).FirstOrDefault(); + } + [Benchmark(Description = "Query (compiled unbuffered)")] + public Post QueryUnbufferedCompiled() + { + Step(); + return _queryUnbufferedCompiled.AsEnumerable(i).FirstOrDefault(); + } + // [Benchmark(Description = "Query (buffered) compiled")] + // public Post CompiledQueryBuffered() + // { + // return _getPosts.ToList().FirstOrDefault(); + // } + // [Benchmark(Description = "Query (unbuffered) compiled")] + // public Post CompiledQueryUnbuffered() + // { + // foreach (var p in _getPostsStream.AsEnumerable()) + // return p; + + // return null; + // } + // [Benchmark(Description = "Query (buffered)")] + // public Post QueryBuffered() + // { + // return _repository.Posts.Limit(QueryLimit).ToList().First(); + // } + // [Benchmark(Description = "Query (unbuffered)")] + // public Post QueryUnbuffered() + // { + // foreach (var p in _repository.Posts.Limit(QueryLimit).ToCommand().AsEnumerable()) + // return p; + + // return null; + // } +} + +public class NextormRepository +{ + public NextormRepository(DbContextBuilder builder) : this(builder.CreateDbContext()) + { + } + public NextormRepository(IDataContext dataContext) + { + Posts = dataContext.Create(config => config.Table("posts")); + } + + public Entity Posts { get; set; } +} diff --git a/benchmarks/Dapper.Tests.Performance/Config.cs b/benchmarks/Dapper.Tests.Performance/Config.cs index b25eb3b82..2fcb41138 100644 --- a/benchmarks/Dapper.Tests.Performance/Config.cs +++ b/benchmarks/Dapper.Tests.Performance/Config.cs @@ -37,8 +37,9 @@ public Config() .WithLaunchCount(1) .WithWarmupCount(2) .WithUnrollFactor(Iterations) - .WithIterationCount(10) + .WithIterationCount(20) ); + // AddJob(Job.Default); Orderer = new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest); Options |= ConfigOptions.JoinSummary; } diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 10ad41cff..58f032b46 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -3,7 +3,7 @@ Dapper.Tests.Performance Dapper Core Performance Suite Exe - net462;net5.0 + net462;net5.0;net8.0 false $(NoWarn);IDE0063;IDE0034;IDE0059;IDE0060 @@ -46,9 +46,21 @@ + - + + + + + + + + + + + + diff --git a/benchmarks/Dapper.Tests.Performance/Program.cs b/benchmarks/Dapper.Tests.Performance/Program.cs index 1e102cf87..e6e91c10a 100644 --- a/benchmarks/Dapper.Tests.Performance/Program.cs +++ b/benchmarks/Dapper.Tests.Performance/Program.cs @@ -44,8 +44,20 @@ public static void Main(string[] args) } else { - WriteLine("Iterations: " + Config.Iterations); - new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); + // var d = new DapperBenchmarks(); + // d.Setup(); + // for (var i = 0; i < 10; i++) + // d.QueryFirstOrDefault(); +#if NET8_0_OR_GREATER + var norm = new NextormBenchmarks(); + norm.Setup(false); + for(var i=0;i<100;i++) + norm.QueryBufferedCompiled(); +#endif + // Console.WriteLine("Press any key to exit"); + // Console.ReadKey(); + // WriteLine("Iterations: " + Config.Iterations); + // new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); } } From 542aa422ecd9d15a081d9695d5b1632dc9587a98 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Sun, 31 Dec 2023 13:00:37 +0300 Subject: [PATCH 03/11] add nextorm query methods --- .../Benchmarks.Nextorm.cs | 55 ++++++------------- .../Dapper.Tests.Performance/Program.cs | 16 +++--- 2 files changed, 25 insertions(+), 46 deletions(-) diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs index 0c8389657..2b7ce61b5 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs @@ -19,9 +19,6 @@ public class NextormBenchmarks : BenchmarkBase private QueryCommand _queryBufferedCompiled; private QueryCommand _queryUnbufferedCompiled; - // private QueryCommand _getPosts; - // private QueryCommand _getPostsStream; - [GlobalSetup] public void GlobalSetup() => Setup(false); public void Setup(bool withLogging) @@ -38,14 +35,11 @@ public void Setup(bool withLogging) _repository = new NextormRepository(builder); - var c = _repository.Posts.Where(it => it.Id == NORM.Param(0)); - _queryBufferedCompiled = c.ToCommand().Compile(); - _queryUnbufferedCompiled = c.ToCommand().Compile(false); - _getPostByIdCompiled = c.FirstOrFirstOrDefaultCommand().Compile(); - _getPostById = _repository.Posts.Where(it => it.Id == NORM.Param(0)).FirstOrFirstOrDefaultCommand(); - // _getPosts = _repository.Posts.Limit(QueryLimit).ToCommand().Compile(true); - // _getPostsStream = _repository.Posts.Limit(QueryLimit).ToCommand().Compile(false); - //Console.WriteLine("Setup complete"); + var cmdBuilder = _repository.Posts.Where(it => it.Id == NORM.Param(0)); + _queryBufferedCompiled = cmdBuilder.ToCommand().Compile(); + _queryUnbufferedCompiled = cmdBuilder.ToCommand().Compile(false); + _getPostById = cmdBuilder.FirstOrFirstOrDefaultCommand(); + _getPostByIdCompiled = _getPostById.Compile(); } [Benchmark(Description = "First")] public Post First() @@ -53,7 +47,18 @@ public Post First() Step(); return _repository.Posts.Where(it => it.Id == i).FirstOrDefault(); } - + [Benchmark(Description = "Query (buffered)")] + public Post QueryBuffered() + { + Step(); + return _repository.Posts.Where(it => it.Id == i).ToList().FirstOrDefault(); + } + [Benchmark(Description = "Query (unbuffered)")] + public Post QueryUnbuffered() + { + Step(); + return _repository.Posts.Where(it => it.Id == i).AsEnumerable().FirstOrDefault(); + } [Benchmark(Description = "First with param")] public Post FirstParam() { @@ -79,32 +84,6 @@ public Post QueryUnbufferedCompiled() Step(); return _queryUnbufferedCompiled.AsEnumerable(i).FirstOrDefault(); } - // [Benchmark(Description = "Query (buffered) compiled")] - // public Post CompiledQueryBuffered() - // { - // return _getPosts.ToList().FirstOrDefault(); - // } - // [Benchmark(Description = "Query (unbuffered) compiled")] - // public Post CompiledQueryUnbuffered() - // { - // foreach (var p in _getPostsStream.AsEnumerable()) - // return p; - - // return null; - // } - // [Benchmark(Description = "Query (buffered)")] - // public Post QueryBuffered() - // { - // return _repository.Posts.Limit(QueryLimit).ToList().First(); - // } - // [Benchmark(Description = "Query (unbuffered)")] - // public Post QueryUnbuffered() - // { - // foreach (var p in _repository.Posts.Limit(QueryLimit).ToCommand().AsEnumerable()) - // return p; - - // return null; - // } } public class NextormRepository diff --git a/benchmarks/Dapper.Tests.Performance/Program.cs b/benchmarks/Dapper.Tests.Performance/Program.cs index e6e91c10a..fc8c2a751 100644 --- a/benchmarks/Dapper.Tests.Performance/Program.cs +++ b/benchmarks/Dapper.Tests.Performance/Program.cs @@ -48,16 +48,16 @@ public static void Main(string[] args) // d.Setup(); // for (var i = 0; i < 10; i++) // d.QueryFirstOrDefault(); -#if NET8_0_OR_GREATER - var norm = new NextormBenchmarks(); - norm.Setup(false); - for(var i=0;i<100;i++) - norm.QueryBufferedCompiled(); -#endif + // #if NET8_0_OR_GREATER + // var norm = new NextormBenchmarks(); + // norm.Setup(false); + // for(var i=0;i<100;i++) + // norm.QueryBufferedCompiled(); + // #endif // Console.WriteLine("Press any key to exit"); // Console.ReadKey(); - // WriteLine("Iterations: " + Config.Iterations); - // new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); + WriteLine("Iterations: " + Config.Iterations); + new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); } } From a2dccdb388a7fd2a978e7acdf10e6d199b42e106 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 13:16:18 +0300 Subject: [PATCH 04/11] add nextorm package --- Directory.Packages.props | 88 +++++++++---------- .../Benchmarks.Nextorm.cs | 2 +- .../Dapper.Tests.Performance.csproj | 9 +- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 06e68e627..e5bd6b8dd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,46 +1,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs index 2b7ce61b5..eb64399eb 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs @@ -30,7 +30,7 @@ public void Setup(bool withLogging) { var logFactory = LoggerFactory.Create(config => config.AddConsole().SetMinimumLevel(LogLevel.Debug)); builder.UseLoggerFactory(logFactory); - builder.LogSensetiveData(true); + builder.LogSensitiveData(true); } _repository = new NextormRepository(builder); diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 58f032b46..750e3d6e0 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -14,7 +14,7 @@ - + @@ -33,7 +33,7 @@ - + $(DefineConstants);NET4X @@ -56,11 +56,10 @@ + - - - + From 41b90e3a6eca85ad301aad6119d58c86f7ea3482 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 13:20:02 +0300 Subject: [PATCH 05/11] restore sources --- benchmarks/Dapper.Tests.Performance/Config.cs | 3 +-- benchmarks/Dapper.Tests.Performance/Program.cs | 12 ------------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/benchmarks/Dapper.Tests.Performance/Config.cs b/benchmarks/Dapper.Tests.Performance/Config.cs index 2fcb41138..b25eb3b82 100644 --- a/benchmarks/Dapper.Tests.Performance/Config.cs +++ b/benchmarks/Dapper.Tests.Performance/Config.cs @@ -37,9 +37,8 @@ public Config() .WithLaunchCount(1) .WithWarmupCount(2) .WithUnrollFactor(Iterations) - .WithIterationCount(20) + .WithIterationCount(10) ); - // AddJob(Job.Default); Orderer = new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest); Options |= ConfigOptions.JoinSummary; } diff --git a/benchmarks/Dapper.Tests.Performance/Program.cs b/benchmarks/Dapper.Tests.Performance/Program.cs index fc8c2a751..1e102cf87 100644 --- a/benchmarks/Dapper.Tests.Performance/Program.cs +++ b/benchmarks/Dapper.Tests.Performance/Program.cs @@ -44,18 +44,6 @@ public static void Main(string[] args) } else { - // var d = new DapperBenchmarks(); - // d.Setup(); - // for (var i = 0; i < 10; i++) - // d.QueryFirstOrDefault(); - // #if NET8_0_OR_GREATER - // var norm = new NextormBenchmarks(); - // norm.Setup(false); - // for(var i=0;i<100;i++) - // norm.QueryBufferedCompiled(); - // #endif - // Console.WriteLine("Press any key to exit"); - // Console.ReadKey(); WriteLine("Iterations: " + Config.Iterations); new BenchmarkSwitcher(typeof(BenchmarkBase).Assembly).Run(args, new Config()); } From b602660c27d24ad61f56875e0c891f244fa067fb Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 14:20:07 +0300 Subject: [PATCH 06/11] reorder packages --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index e5bd6b8dd..36a65f02a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,8 +9,8 @@ - + From de1da599f33d1866767a5024be109c8f029373a2 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 14:37:15 +0300 Subject: [PATCH 07/11] resolve conflicts --- Directory.Packages.props | 1 + 1 file changed, 1 insertion(+) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4ddd3896f..4bd3b2f3b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,6 +9,7 @@ + From 902799f4ed5fc65d88f4b003fcdd44a30cf5e686 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 19:36:11 +0300 Subject: [PATCH 08/11] review fixes --- benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs | 5 ++--- .../Dapper.Tests.Performance.csproj | 8 -------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs index eb64399eb..3bfa801b5 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs @@ -1,9 +1,7 @@ -using System; +#if !NET4X using System.ComponentModel; using System.Linq; using BenchmarkDotNet.Attributes; -using DevExpress.Data.Access; -using System.Data.SqlClient; using Microsoft.Extensions.Logging; using nextorm.core; using nextorm.sqlserver; @@ -98,3 +96,4 @@ public NextormRepository(IDataContext dataContext) public Entity Posts { get; set; } } +#endif diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index b7908b4c7..07c02067b 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -3,7 +3,6 @@ Dapper.Tests.Performance Dapper Core Performance Suite Exe - net462;net5.0;net8.0 net462;net8.0 false $(NoWarn);IDE0063;IDE0034;IDE0059;IDE0060 @@ -47,16 +46,9 @@ - - - - - - - From 89974af0a18183b84213330d1973c72cdbfbe77f Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 19:53:15 +0300 Subject: [PATCH 09/11] remove VersionOverride --- .../Dapper.Tests.Performance/Dapper.Tests.Performance.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 07c02067b..214864cef 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -50,7 +50,7 @@ - + From 48d8ab8cac344973010f6b3103c7ca6dacc14d04 Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Tue, 9 Jan 2024 20:16:53 +0300 Subject: [PATCH 10/11] add PackageVersions to Directory.Packages.props --- Directory.Packages.props | 7 +++++-- .../Dapper.Tests.Performance.csproj | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4bd3b2f3b..43dfd1e85 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,7 +10,7 @@ - + @@ -43,5 +43,8 @@ - + + + + \ No newline at end of file diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 214864cef..477949fec 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -51,8 +51,8 @@ - - - + + + From eacedf81596480e3441ec3df3b4e7475785b5feb Mon Sep 17 00:00:00 2001 From: Alexey Shirshov Date: Thu, 8 Feb 2024 19:21:03 +0300 Subject: [PATCH 11/11] upgrade to 1.0.2-alpha --- Directory.Packages.props | 2 +- .../Benchmarks.Nextorm.cs | 40 ++++++++++--------- .../Dapper.Tests.Performance.csproj | 4 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 43dfd1e85..01200e689 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -38,7 +38,7 @@ - + diff --git a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs index 3bfa801b5..92f72457d 100644 --- a/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs +++ b/benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs @@ -12,10 +12,10 @@ namespace Dapper.Tests.Performance; public class NextormBenchmarks : BenchmarkBase { private NextormRepository _repository; - private QueryCommand _getPostByIdCompiled; + private IPreparedQueryCommand _getPostByIdPrepared; private QueryCommand _getPostById; - private QueryCommand _queryBufferedCompiled; - private QueryCommand _queryUnbufferedCompiled; + private IPreparedQueryCommand _queryBufferedPrepared; + private IPreparedQueryCommand _queryUnbufferedPrepared; [GlobalSetup] public void GlobalSetup() => Setup(false); @@ -34,12 +34,12 @@ public void Setup(bool withLogging) _repository = new NextormRepository(builder); var cmdBuilder = _repository.Posts.Where(it => it.Id == NORM.Param(0)); - _queryBufferedCompiled = cmdBuilder.ToCommand().Compile(); - _queryUnbufferedCompiled = cmdBuilder.ToCommand().Compile(false); + _queryBufferedPrepared = cmdBuilder.ToCommand().Prepare(); + _queryUnbufferedPrepared = cmdBuilder.ToCommand().Prepare(false); _getPostById = cmdBuilder.FirstOrFirstOrDefaultCommand(); - _getPostByIdCompiled = _getPostById.Compile(); + _getPostByIdPrepared = _getPostById.Prepare(); } - [Benchmark(Description = "First")] + [Benchmark(Description = "QueryFirstOrDefault")] public Post First() { Step(); @@ -55,45 +55,49 @@ public Post QueryBuffered() public Post QueryUnbuffered() { Step(); - return _repository.Posts.Where(it => it.Id == i).AsEnumerable().FirstOrDefault(); + return _repository.Posts.Where(it => it.Id == i).ToEnumerable().FirstOrDefault(); } - [Benchmark(Description = "First with param")] + [Benchmark(Description = "QueryFirstOrDefault with param")] public Post FirstParam() { Step(); return _getPostById.FirstOrDefault(i); } - [Benchmark(Description = "First compiled")] - public Post FirstCompiled() + [Benchmark(Description = "QueryFirstOrDefault prepared")] + public Post FirstPrepared() { Step(); - return _getPostByIdCompiled.FirstOrDefault(i); + return _getPostByIdPrepared.FirstOrDefault(_repository.DataContext, i); } - [Benchmark(Description = "Query (compiled buffered)")] - public Post QueryBufferedCompiled() + [Benchmark(Description = "Query (buffered prepared)")] + public Post QueryBufferedPrepared() { Step(); - return _queryBufferedCompiled.ToList(i).FirstOrDefault(); + return _queryBufferedPrepared.ToList(_repository.DataContext, i).FirstOrDefault(); } - [Benchmark(Description = "Query (compiled unbuffered)")] - public Post QueryUnbufferedCompiled() + [Benchmark(Description = "Query (unbuffered prepared)")] + public Post QueryUnbufferedPrepared() { Step(); - return _queryUnbufferedCompiled.AsEnumerable(i).FirstOrDefault(); + return _queryUnbufferedPrepared.ToEnumerable(_repository.DataContext, i).FirstOrDefault(); } } public class NextormRepository { + private readonly IDataContext _dataContext; + public NextormRepository(DbContextBuilder builder) : this(builder.CreateDbContext()) { } public NextormRepository(IDataContext dataContext) { Posts = dataContext.Create(config => config.Table("posts")); + _dataContext = dataContext; } public Entity Posts { get; set; } + public IDataContext DataContext => _dataContext; } #endif diff --git a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 477949fec..db800004d 100644 --- a/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/benchmarks/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -49,7 +49,9 @@ - + + +