Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nextorm to benchmarks #2025

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
10 changes: 7 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />

<PackageVersion Include="nextorm.sqlserver" Version="1.0.1-alpha" />

<!-- tests -->
<PackageVersion Include="Belgrade.Sql.Client" Version="1.1.4" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.11" />
Expand Down Expand Up @@ -37,10 +38,13 @@
<PackageVersion Include="SqlMarshal" Version="0.4.4" />
<PackageVersion Include="SubSonic" Version="3.0.0.4" />
<PackageVersion Include="Susanoo.SqlServer" Version="1.2.4.2" />
<PackageVersion Include="System.Data.SqlClient" Version="4.8.5" />
<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
<PackageVersion Include="System.Data.SQLite" Version="1.0.118" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="xunit" Version="2.6.4" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="8.0.0" />
<PackageVersion Include="OneOf" Version="3.0.263" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Linq;

namespace Dapper.Tests.Performance
Expand All @@ -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")]
Expand Down
103 changes: 103 additions & 0 deletions benchmarks/Dapper.Tests.Performance/Benchmarks.Nextorm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#if !NET4X
using System.ComponentModel;
using System.Linq;
using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.Logging;
using nextorm.core;
using nextorm.sqlserver;

namespace Dapper.Tests.Performance;

[Description("Nextorm")]
public class NextormBenchmarks : BenchmarkBase
{
private NextormRepository _repository;
private IPreparedQueryCommand<Post> _getPostByIdPrepared;
private QueryCommand<Post> _getPostById;
private IPreparedQueryCommand<Post> _queryBufferedPrepared;
private IPreparedQueryCommand<Post> _queryUnbufferedPrepared;

[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.LogSensitiveData(true);
}

_repository = new NextormRepository(builder);

var cmdBuilder = _repository.Posts.Where(it => it.Id == NORM.Param<int>(0));
_queryBufferedPrepared = cmdBuilder.ToCommand().Prepare();
_queryUnbufferedPrepared = cmdBuilder.ToCommand().Prepare(false);
_getPostById = cmdBuilder.FirstOrFirstOrDefaultCommand();
_getPostByIdPrepared = _getPostById.Prepare();
}
[Benchmark(Description = "QueryFirstOrDefault<T>")]
public Post First()
{
Step();
return _repository.Posts.Where(it => it.Id == i).FirstOrDefault();
}
[Benchmark(Description = "Query<T> (buffered)")]
public Post QueryBuffered()
{
Step();
return _repository.Posts.Where(it => it.Id == i).ToList().FirstOrDefault();
}
[Benchmark(Description = "Query<T> (unbuffered)")]
public Post QueryUnbuffered()
{
Step();
return _repository.Posts.Where(it => it.Id == i).ToEnumerable().FirstOrDefault();
}
[Benchmark(Description = "QueryFirstOrDefault<T> with param")]
public Post FirstParam()
{
Step();
return _getPostById.FirstOrDefault(i);
}

[Benchmark(Description = "QueryFirstOrDefault<T> prepared")]
public Post FirstPrepared()
{
Step();
return _getPostByIdPrepared.FirstOrDefault(_repository.DataContext, i);
}
[Benchmark(Description = "Query<T> (buffered prepared)")]
public Post QueryBufferedPrepared()
{
Step();
return _queryBufferedPrepared.ToList(_repository.DataContext, i).FirstOrDefault();
}
[Benchmark(Description = "Query<T> (unbuffered prepared)")]
public Post QueryUnbufferedPrepared()
{
Step();
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<Post>(config => config.Table("posts"));
_dataContext = dataContext;
}

public Entity<Post> Posts { get; set; }
public IDataContext DataContext => _dataContext;
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Belgrade.Sql.Client" />
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="DevExpress.Xpo" />
<PackageReference Include="EntityFramework" VersionOverride="6.4.4"/>
<PackageReference Include="EntityFramework" VersionOverride="6.4.4" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" />
<PackageReference Include="linq2db.SqlServer" />
<PackageReference Include="MySqlConnector" />
Expand All @@ -33,7 +33,7 @@
<EmbeddedResource Include="NHibernate\*.xml" />
<Compile Update="Benchmarks.*.cs" DependentUpon="Benchmarks.cs" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net462'">
<DefineConstants>$(DefineConstants);NET4X</DefineConstants>
</PropertyGroup>
Expand All @@ -48,7 +48,13 @@
<Reference Include="System.Data.Linq" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Norm.net" />
<Reference Include="C:\Users\alexey.CORP\sources\repos\nextorm\nextorm.sqlserver\bin\Release\net8.0\nextorm.core.dll"/>
<Reference Include="C:\Users\alexey.CORP\sources\repos\nextorm\nextorm.sqlserver\bin\Release\net8.0\nextorm.sqlserver.dll"/>
<!-- <PackageReference Include="nextorm.sqlserver" /> -->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" />
<PackageReference Include="OneOf" />
</ItemGroup>
</Project>