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