Commit 0ec089b7 authored by Nick Craver's avatar Nick Craver

Benchmarks: normalize names and give ORMs better names via [Description]

parent b262cb33
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Belgrade.SqlClient.SqlDb; using Belgrade.SqlClient.SqlDb;
using System.Threading.Tasks;
using Belgrade.SqlClient; using Belgrade.SqlClient;
using System.ComponentModel;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("Belgrade")]
public class BelgradeBenchmarks : BenchmarkBase public class BelgradeBenchmarks : BenchmarkBase
{ {
private QueryMapper _mapper; private QueryMapper _mapper;
......
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
using System.ComponentModel;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("Dapper")]
public class DapperBenchmarks : BenchmarkBase public class DapperBenchmarks : BenchmarkBase
{ {
[GlobalSetup] [GlobalSetup]
......
using BenchmarkDotNet.Attributes; using System.ComponentModel;
using BenchmarkDotNet.Attributes;
using Dapper.Tests.Performance.Dashing; using Dapper.Tests.Performance.Dashing;
using Dashing; using Dashing;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("Dashing")]
public class DashingBenchmarks : BenchmarkBase public class DashingBenchmarks : BenchmarkBase
{ {
private ISession session; private ISession Session;
[GlobalSetup] [GlobalSetup]
public void Setup() public void Setup()
...@@ -14,14 +16,14 @@ public void Setup() ...@@ -14,14 +16,14 @@ public void Setup()
BaseSetup(); BaseSetup();
var configuration = new DashingConfiguration(); var configuration = new DashingConfiguration();
var database = new SqlDatabase(configuration, ConnectionString); var database = new SqlDatabase(configuration, ConnectionString);
this.session = database.BeginTransactionLessSession(_connection); Session = database.BeginTransactionLessSession(_connection);
} }
[Benchmark(Description = "Get By Id")] [Benchmark(Description = "Get")]
public Dashing.Post QueryBuffered() public Dashing.Post Get()
{ {
Step(); Step();
return session.Get<Dashing.Post>(i); return Session.Get<Dashing.Post>(i);
} }
} }
} }
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using System.ComponentModel;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("EF 6")]
public class EF6Benchmarks : BenchmarkBase public class EF6Benchmarks : BenchmarkBase
{ {
private EntityFramework.EFContext Context; private EntityFramework.EFContext Context;
...@@ -14,8 +16,8 @@ public void Setup() ...@@ -14,8 +16,8 @@ public void Setup()
Context = new EntityFramework.EFContext(_connection); Context = new EntityFramework.EFContext(_connection);
} }
[Benchmark(Description = "Normal")] [Benchmark(Description = "First")]
public Post Normal() public Post First()
{ {
Step(); Step();
return Context.Posts.First(p => p.Id == i); return Context.Posts.First(p => p.Id == i);
...@@ -28,11 +30,11 @@ public Post SqlQuery() ...@@ -28,11 +30,11 @@ public Post SqlQuery()
return Context.Database.SqlQuery<Post>("select * from Posts where Id = {0}", i).First(); return Context.Database.SqlQuery<Post>("select * from Posts where Id = {0}", i).First();
} }
[Benchmark(Description = "No Tracking")] [Benchmark(Description = "First (No Tracking)")]
public Post NoTracking() public Post NoTracking()
{ {
Step(); Step();
return Context.Posts.AsNoTracking().First(p => p.Id == i); return Context.Posts.AsNoTracking().First(p => p.Id == i);
} }
} }
} }
\ No newline at end of file
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
using Dapper.Tests.Performance.EntityFrameworkCore; using Dapper.Tests.Performance.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.ComponentModel;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("EF Core")]
public class EFCoreBenchmarks : BenchmarkBase public class EFCoreBenchmarks : BenchmarkBase
{ {
private EFCoreContext Context; private EFCoreContext Context;
private static readonly Func<EFCoreContext, int, Post> compiledQuery = private static readonly Func<EFCoreContext, int, Post> compiledQuery =
EF.CompileQuery((EFCoreContext ctx, int id) => ctx.Posts.First(p => p.Id == id)); EF.CompileQuery((EFCoreContext ctx, int id) => ctx.Posts.First(p => p.Id == id));
...@@ -19,14 +22,14 @@ public void Setup() ...@@ -19,14 +22,14 @@ public void Setup()
Context = new EFCoreContext(_connection.ConnectionString); Context = new EFCoreContext(_connection.ConnectionString);
} }
[Benchmark(Description = "Normal")] [Benchmark(Description = "First")]
public Post Normal() public Post First()
{ {
Step(); Step();
return Context.Posts.First(p => p.Id == i); return Context.Posts.First(p => p.Id == i);
} }
[Benchmark(Description = "Compiled")] [Benchmark(Description = "First (Compiled)")]
public Post Compiled() public Post Compiled()
{ {
Step(); Step();
...@@ -40,7 +43,7 @@ public Post SqlQuery() ...@@ -40,7 +43,7 @@ public Post SqlQuery()
return Context.Posts.FromSql("select * from Posts where Id = {0}", i).First(); return Context.Posts.FromSql("select * from Posts where Id = {0}", i).First();
} }
[Benchmark(Description = "No Tracking")] [Benchmark(Description = "First (No Tracking)")]
public Post NoTracking() public Post NoTracking()
{ {
Step(); Step();
......
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using System; using System;
using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("Hand Coded")]
public class HandCodedBenchmarks : BenchmarkBase public class HandCodedBenchmarks : BenchmarkBase
{ {
private SqlCommand _postCommand; private SqlCommand _postCommand;
...@@ -56,7 +58,7 @@ public Post SqlCommand() ...@@ -56,7 +58,7 @@ public Post SqlCommand()
using (var reader = _postCommand.ExecuteReader()) using (var reader = _postCommand.ExecuteReader())
{ {
reader.Read(); reader.Read();
var post = new Post return new Post
{ {
Id = reader.GetInt32(0), Id = reader.GetInt32(0),
Text = reader.GetNullableString(1), Text = reader.GetNullableString(1),
...@@ -73,7 +75,6 @@ public Post SqlCommand() ...@@ -73,7 +75,6 @@ public Post SqlCommand()
Counter8 = reader.IsDBNull(11) ? null : (int?)reader.GetInt32(11), Counter8 = reader.IsDBNull(11) ? null : (int?)reader.GetInt32(11),
Counter9 = reader.IsDBNull(12) ? null : (int?)reader.GetInt32(12) Counter9 = reader.IsDBNull(12) ? null : (int?)reader.GetInt32(12)
}; };
return post;
} }
} }
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
using Dapper.Tests.Performance.Linq2Db; using Dapper.Tests.Performance.Linq2Db;
using LinqToDB; using LinqToDB;
using LinqToDB.Data; using LinqToDB.Data;
using System.ComponentModel;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("LINQ to DB")]
public class Linq2DBBenchmarks : BenchmarkBase public class Linq2DBBenchmarks : BenchmarkBase
{ {
private Linq2DBContext _dbContext; private Linq2DBContext _dbContext;
...@@ -22,22 +24,22 @@ public void Setup() ...@@ -22,22 +24,22 @@ public void Setup()
_dbContext = new Linq2DBContext(); _dbContext = new Linq2DBContext();
} }
[Benchmark(Description = "Normal")] [Benchmark(Description = "First")]
public Post Normal() public Post First()
{ {
Step(); Step();
return _dbContext.Posts.First(p => p.Id == i); return _dbContext.Posts.First(p => p.Id == i);
} }
[Benchmark(Description = "Compiled")] [Benchmark(Description = "First (Compiled)")]
public Post Compiled() public Post Compiled()
{ {
Step(); Step();
return compiledQuery(_dbContext, i); return compiledQuery(_dbContext, i);
} }
[Benchmark(Description = "SqlQuery")] [Benchmark(Description = "Query<T>")]
public Post SqlQuery() public Post Query()
{ {
Step(); Step();
return _dbContext.Query<Post>("select * from Posts where Id = @id", new { id = i }).First(); return _dbContext.Query<Post>("select * from Posts where Id = @id", new { id = i }).First();
......
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Dapper.Tests.Performance.Linq2Sql; using Dapper.Tests.Performance.Linq2Sql;
using System; using System;
using System.ComponentModel;
using System.Data.Linq; using System.Data.Linq;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("LINQ to SQL")]
public class Linq2SqlBenchmarks : BenchmarkBase public class Linq2SqlBenchmarks : BenchmarkBase
{ {
private DataClassesDataContext Linq2SqlContext; private DataClassesDataContext Linq2SqlContext;
private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery = private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery =
CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id)); CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id));
...@@ -19,14 +22,14 @@ public void Setup() ...@@ -19,14 +22,14 @@ public void Setup()
Linq2SqlContext = new DataClassesDataContext(_connection); Linq2SqlContext = new DataClassesDataContext(_connection);
} }
[Benchmark(Description = "Normal")] [Benchmark(Description = "First")]
public Linq2Sql.Post Normal() public Linq2Sql.Post First()
{ {
Step(); Step();
return Linq2SqlContext.Posts.First(p => p.Id == i); return Linq2SqlContext.Posts.First(p => p.Id == i);
} }
[Benchmark(Description = "Compiled")] [Benchmark(Description = "First (Compiled)")]
public Linq2Sql.Post Compiled() public Linq2Sql.Post Compiled()
{ {
Step(); Step();
...@@ -40,4 +43,4 @@ public Post ExecuteQuery() ...@@ -40,4 +43,4 @@ public Post ExecuteQuery()
return Linq2SqlContext.ExecuteQuery<Post>("select * from Posts where Id = {0}", i).First(); return Linq2SqlContext.ExecuteQuery<Post>("select * from Posts where Id = {0}", i).First();
} }
} }
} }
\ No newline at end of file
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Massive; using Massive;
using System.ComponentModel;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("Massive")]
public class MassiveBenchmarks : BenchmarkBase public class MassiveBenchmarks : BenchmarkBase
{ {
private DynamicModel _model; private DynamicModel _model;
...@@ -22,4 +24,4 @@ public dynamic QueryDynamic() ...@@ -22,4 +24,4 @@ public dynamic QueryDynamic()
return _model.Query("select * from Posts where Id = @0", _connection, i).First(); return _model.Query("select * from Posts where Id = @0", _connection, i).First();
} }
} }
} }
\ No newline at end of file
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using PetaPoco; using PetaPoco;
using System.ComponentModel;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("PetaPoco")]
public class PetaPocoBenchmarks : BenchmarkBase public class PetaPocoBenchmarks : BenchmarkBase
{ {
private Database _db, _dbFast; private Database _db, _dbFast;
...@@ -21,18 +23,18 @@ public void Setup() ...@@ -21,18 +23,18 @@ public void Setup()
_dbFast.ForceDateTimesToUtc = false; _dbFast.ForceDateTimesToUtc = false;
} }
[Benchmark(Description = "Fetch<Post>")] [Benchmark(Description = "Fetch<T>")]
public Post Fetch() public Post Fetch()
{ {
Step(); Step();
return _db.Fetch<Post>("SELECT * from Posts where Id=@0", i).First(); return _db.Fetch<Post>("SELECT * from Posts where Id=@0", i).First();
} }
[Benchmark(Description = "Fetch<Post> (Fast)")] [Benchmark(Description = "Fetch<T> (Fast)")]
public Post FetchFast() public Post FetchFast()
{ {
Step(); Step();
return _dbFast.Fetch<Post>("SELECT * from Posts where Id=@0", i).First(); return _dbFast.Fetch<Post>("SELECT * from Posts where Id=@0", i).First();
} }
} }
} }
\ No newline at end of file
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using System.ComponentModel;
using System.Data; using System.Data;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("ServiceStack")]
public class ServiceStackBenchmarks : BenchmarkBase public class ServiceStackBenchmarks : BenchmarkBase
{ {
private IDbConnection _db; private IDbConnection _db;
...@@ -16,11 +18,11 @@ public void Setup() ...@@ -16,11 +18,11 @@ public void Setup()
_db = dbFactory.Open(); _db = dbFactory.Open();
} }
[Benchmark(Description = "SingleById")] [Benchmark(Description = "SingleById<T>")]
public Post Query() public Post Query()
{ {
Step(); Step();
return _db.SingleById<Post>(i); return _db.SingleById<Post>(i);
} }
} }
} }
\ No newline at end of file
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Susanoo; using Susanoo;
using Susanoo.Processing; using Susanoo.Processing;
using System.ComponentModel;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
namespace Dapper.Tests.Performance namespace Dapper.Tests.Performance
{ {
[Description("Susanoo")]
public class SusanooBenchmarks : BenchmarkBase public class SusanooBenchmarks : BenchmarkBase
{ {
private DatabaseManager _db; private DatabaseManager _db;
private static readonly ISingleResultSetCommandProcessor<dynamic, Post> _cmd = private static readonly ISingleResultSetCommandProcessor<dynamic, Post> _cmd =
CommandManager.Instance.DefineCommand("SELECT * FROM Posts WHERE Id = @Id", CommandType.Text) CommandManager.Instance.DefineCommand("SELECT * FROM Posts WHERE Id = @Id", CommandType.Text)
.DefineResults<Post>() .DefineResults<Post>()
.Realize(); .Realize();
private static readonly ISingleResultSetCommandProcessor<dynamic, dynamic> _cmdDynamic = private static readonly ISingleResultSetCommandProcessor<dynamic, dynamic> _cmdDynamic =
CommandManager.Instance.DefineCommand("SELECT * FROM Posts WHERE Id = @Id", CommandType.Text) CommandManager.Instance.DefineCommand("SELECT * FROM Posts WHERE Id = @Id", CommandType.Text)
.DefineResults<dynamic>() .DefineResults<dynamic>()
...@@ -25,7 +29,7 @@ public void Setup() ...@@ -25,7 +29,7 @@ public void Setup()
_db = new DatabaseManager(_connection); _db = new DatabaseManager(_connection);
} }
[Benchmark(Description = "Mapping Cache")] [Benchmark(Description = "Execute<T> (Cache)")]
public Post MappingCache() public Post MappingCache()
{ {
Step(); Step();
...@@ -35,7 +39,7 @@ public Post MappingCache() ...@@ -35,7 +39,7 @@ public Post MappingCache()
.Execute(_db, new { Id = i }).First(); .Execute(_db, new { Id = i }).First();
} }
[Benchmark(Description = "Mapping Cache (dynamic)")] [Benchmark(Description = "Execute<dynamic> (Cache)")]
public dynamic MappingCacheDynamic() public dynamic MappingCacheDynamic()
{ {
Step(); Step();
...@@ -45,18 +49,18 @@ public dynamic MappingCacheDynamic() ...@@ -45,18 +49,18 @@ public dynamic MappingCacheDynamic()
.Execute(_db, new { Id = i }).First(); .Execute(_db, new { Id = i }).First();
} }
[Benchmark(Description = "Mapping Static")] [Benchmark(Description = "Execute<T> (Static)")]
public Post MappingStatic() public Post MappingStatic()
{ {
Step(); Step();
return _cmd.Execute(_db, new { Id = i }).First(); return _cmd.Execute(_db, new { Id = i }).First();
} }
[Benchmark(Description = "Mapping Static (dynamic)")] [Benchmark(Description = "Execut<dynamic> (Static)")]
public dynamic MappingStaticDynamic() public dynamic MappingStaticDynamic()
{ {
Step(); Step();
return _cmdDynamic.Execute(_db, new { Id = i }).First(); return _cmdDynamic.Execute(_db, new { Id = i }).First();
} }
} }
} }
\ No newline at end of file
using BenchmarkDotNet.Columns; using System.ComponentModel;
using System.Reflection;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Reports; using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running; using BenchmarkDotNet.Running;
...@@ -11,7 +13,12 @@ public class ORMColum : IColumn ...@@ -11,7 +13,12 @@ public class ORMColum : IColumn
public string Legend => "The object/relational mapper being tested"; public string Legend => "The object/relational mapper being tested";
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false; public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false;
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => benchmarkCase.Descriptor.WorkloadMethod.DeclaringType.Name.Replace("Benchmarks", string.Empty); public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
{
var type = benchmarkCase.Descriptor.WorkloadMethod.DeclaringType;
return type.GetCustomAttribute<DescriptionAttribute>()?.Description ?? type.Name.Replace("Benchmarks", string.Empty);
}
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style) => GetValue(summary, benchmarkCase); public string GetValue(Summary summary, BenchmarkCase benchmarkCase, ISummaryStyle style) => GetValue(summary, benchmarkCase);
public bool IsAvailable(Summary summary) => true; public bool IsAvailable(Summary summary) => true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment