Commit fb443385 authored by Nick Craver's avatar Nick Craver

Try and use BenchmarkDotNet correctly

OperationsPerInvoke is an informational, not instructional property.
What we actually want is the UnrollFactor. Moved into the job definition
to simplify things.
parent f39cff33
...@@ -15,7 +15,7 @@ public void Setup() ...@@ -15,7 +15,7 @@ public void Setup()
_mapper = new QueryMapper(ConnectionString); _mapper = new QueryMapper(ConnectionString);
} }
[Benchmark(Description = "ExecuteReader", OperationsPerInvoke = Iterations)] [Benchmark(Description = "ExecuteReader")]
public async Task ExecuteReader() public async Task ExecuteReader()
{ {
Step(); Step();
......
...@@ -12,46 +12,46 @@ public void Setup() ...@@ -12,46 +12,46 @@ public void Setup()
BaseSetup(); BaseSetup();
} }
[Benchmark(Description = "Query<T> (buffered)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Query<T> (buffered)")]
public Post QueryBuffered() public Post QueryBuffered()
{ {
Step(); Step();
return _connection.Query<Post>("select * from Posts where Id = @Id", new { Id = i }, buffered: true).First(); return _connection.Query<Post>("select * from Posts where Id = @Id", new { Id = i }, buffered: true).First();
} }
[Benchmark(Description = "Query<dyanmic> (buffered)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Query<dyanmic> (buffered)")]
public dynamic QueryBufferedDynamic() public dynamic QueryBufferedDynamic()
{ {
Step(); Step();
return _connection.Query("select * from Posts where Id = @Id", new { Id = i }, buffered: true).First(); return _connection.Query("select * from Posts where Id = @Id", new { Id = i }, buffered: true).First();
} }
[Benchmark(Description = "Query<T> (unbuffered)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Query<T> (unbuffered)")]
public Post QueryUnbuffered() public Post QueryUnbuffered()
{ {
Step(); Step();
return _connection.Query<Post>("select * from Posts where Id = @Id", new { Id = i }, buffered: false).First(); return _connection.Query<Post>("select * from Posts where Id = @Id", new { Id = i }, buffered: false).First();
} }
[Benchmark(Description = "Query<dyanmic> (unbuffered)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Query<dyanmic> (unbuffered)")]
public dynamic QueryUnbufferedDynamic() public dynamic QueryUnbufferedDynamic()
{ {
Step(); Step();
return _connection.Query("select * from Posts where Id = @Id", new { Id = i }, buffered: false).First(); return _connection.Query("select * from Posts where Id = @Id", new { Id = i }, buffered: false).First();
} }
[Benchmark(Description = "QueryFirstOrDefault<T>", OperationsPerInvoke = Iterations)] [Benchmark(Description = "QueryFirstOrDefault<T>")]
public Post QueryFirstOrDefault() public Post QueryFirstOrDefault()
{ {
Step(); Step();
return _connection.QueryFirstOrDefault<Post>("select * from Posts where Id = @Id", new { Id = i }); return _connection.QueryFirstOrDefault<Post>("select * from Posts where Id = @Id", new { Id = i });
} }
[Benchmark(Description = "QueryFirstOrDefault<dyanmic>", OperationsPerInvoke = Iterations)] [Benchmark(Description = "QueryFirstOrDefault<dyanmic>")]
public dynamic QueryFirstOrDefaultDynamic() public dynamic QueryFirstOrDefaultDynamic()
{ {
Step(); Step();
return _connection.QueryFirstOrDefault("select * from Posts where Id = @Id", new { Id = i }).First(); return _connection.QueryFirstOrDefault("select * from Posts where Id = @Id", new { Id = i }).First();
} }
[Benchmark(Description = "Contrib Get<T>", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Contrib Get<T>")]
public Post ContribGet() public Post ContribGet()
{ {
Step(); Step();
......
...@@ -19,21 +19,21 @@ public void Setup() ...@@ -19,21 +19,21 @@ public void Setup()
Context = new EntityFramework.EFContext(_connection); Context = new EntityFramework.EFContext(_connection);
} }
[Benchmark(Description = "Normal", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Normal")]
public Post Normal() public Post Normal()
{ {
Step(); Step();
return Context.Posts.First(p => p.Id == i); return Context.Posts.First(p => p.Id == i);
} }
[Benchmark(Description = "SqlQuery", OperationsPerInvoke = Iterations)] [Benchmark(Description = "SqlQuery")]
public Post SqlQuery() public Post SqlQuery()
{ {
Step(); Step();
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", OperationsPerInvoke = Iterations)] [Benchmark(Description = "No Tracking")]
public Post NoTracking() public Post NoTracking()
{ {
Step(); Step();
......
...@@ -47,7 +47,7 @@ public void Setup() ...@@ -47,7 +47,7 @@ public void Setup()
#endif #endif
} }
[Benchmark(Description = "SqlCommand", OperationsPerInvoke = Iterations, Baseline = true)] [Benchmark(Description = "SqlCommand", Baseline = true)]
public Post SqlCommand() public Post SqlCommand()
{ {
Step(); Step();
...@@ -75,7 +75,7 @@ public Post SqlCommand() ...@@ -75,7 +75,7 @@ public Post SqlCommand()
} }
} }
[Benchmark(Description = "DataTable", OperationsPerInvoke = Iterations)] [Benchmark(Description = "DataTable")]
public dynamic DataTableDynamic() public dynamic DataTableDynamic()
{ {
Step(); Step();
......
...@@ -19,21 +19,21 @@ public void Setup() ...@@ -19,21 +19,21 @@ public void Setup()
Linq2SqlContext = new DataClassesDataContext(_connection); Linq2SqlContext = new DataClassesDataContext(_connection);
} }
[Benchmark(Description = "Normal", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Normal")]
public Linq2Sql.Post Normal() public Linq2Sql.Post Normal()
{ {
Step(); Step();
return Linq2SqlContext.Posts.First(p => p.Id == i); return Linq2SqlContext.Posts.First(p => p.Id == i);
} }
[Benchmark(Description = "Compiled", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Compiled")]
public Linq2Sql.Post Compiled() public Linq2Sql.Post Compiled()
{ {
Step(); Step();
return compiledQuery(Linq2SqlContext, i); return compiledQuery(Linq2SqlContext, i);
} }
[Benchmark(Description = "ExecuteQuery", OperationsPerInvoke = Iterations)] [Benchmark(Description = "ExecuteQuery")]
public Post ExecuteQuery() public Post ExecuteQuery()
{ {
Step(); Step();
......
...@@ -15,7 +15,7 @@ public void Setup() ...@@ -15,7 +15,7 @@ public void Setup()
_model = new DynamicModel(ConnectionString); _model = new DynamicModel(ConnectionString);
} }
[Benchmark(Description = "Query (dynamic)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Query (dynamic)")]
public dynamic QueryDynamic() public dynamic QueryDynamic()
{ {
Step(); Step();
......
...@@ -24,7 +24,7 @@ public void Setup() ...@@ -24,7 +24,7 @@ public void Setup()
_get = NHibernateHelper.OpenSession(); _get = NHibernateHelper.OpenSession();
} }
[Benchmark(Description = "SQL", OperationsPerInvoke = Iterations)] [Benchmark(Description = "SQL")]
public Post SQL() public Post SQL()
{ {
Step(); Step();
...@@ -34,7 +34,7 @@ public Post SQL() ...@@ -34,7 +34,7 @@ public Post SQL()
.List<Post>()[0]; .List<Post>()[0];
} }
[Benchmark(Description = "HQL", OperationsPerInvoke = Iterations)] [Benchmark(Description = "HQL")]
public Post HQL() public Post HQL()
{ {
Step(); Step();
...@@ -43,7 +43,7 @@ public Post HQL() ...@@ -43,7 +43,7 @@ public Post HQL()
.List<Post>()[0]; .List<Post>()[0];
} }
[Benchmark(Description = "Criteria", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Criteria")]
public Post Criteria() public Post Criteria()
{ {
Step(); Step();
...@@ -52,14 +52,14 @@ public Post Criteria() ...@@ -52,14 +52,14 @@ public Post Criteria()
.List<Post>()[0]; .List<Post>()[0];
} }
[Benchmark(Description = "LINQ", OperationsPerInvoke = Iterations)] [Benchmark(Description = "LINQ")]
public Post LINQ() public Post LINQ()
{ {
Step(); Step();
return _linq.Query<Post>().First(p => p.Id == i); return _linq.Query<Post>().First(p => p.Id == i);
} }
[Benchmark(Description = "Get<T>", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Get<T>")]
public Post Get() public Post Get()
{ {
Step(); Step();
......
...@@ -21,14 +21,14 @@ public void Setup() ...@@ -21,14 +21,14 @@ public void Setup()
_dbFast.ForceDateTimesToUtc = false; _dbFast.ForceDateTimesToUtc = false;
} }
[Benchmark(Description = "Fetch<Post>", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Fetch<Post>")]
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)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Fetch<Post> (Fast)")]
public Post FetchFast() public Post FetchFast()
{ {
Step(); Step();
......
...@@ -16,7 +16,7 @@ public void Setup() ...@@ -16,7 +16,7 @@ public void Setup()
_db = dbFactory.Open(); _db = dbFactory.Open();
} }
[Benchmark(Description = "SingleById", OperationsPerInvoke = Iterations)] [Benchmark(Description = "SingleById")]
public Post Query() public Post Query()
{ {
Step(); Step();
......
...@@ -13,7 +13,7 @@ public void Setup() ...@@ -13,7 +13,7 @@ public void Setup()
_sdb = Simple.Data.Database.OpenConnection(ConnectionString); _sdb = Simple.Data.Database.OpenConnection(ConnectionString);
} }
[Benchmark(Description = "FindById", OperationsPerInvoke = Iterations)] [Benchmark(Description = "FindById")]
public dynamic QueryDynamic() public dynamic QueryDynamic()
{ {
Step(); Step();
......
...@@ -25,7 +25,7 @@ public void Setup() ...@@ -25,7 +25,7 @@ public void Setup()
_db = new DatabaseManager(_connection); _db = new DatabaseManager(_connection);
} }
[Benchmark(Description = "Mapping Cache", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Mapping Cache")]
public Post MappingCache() public Post MappingCache()
{ {
Step(); Step();
...@@ -35,7 +35,7 @@ public Post MappingCache() ...@@ -35,7 +35,7 @@ public Post MappingCache()
.Execute(_db, new { Id = i }).First(); .Execute(_db, new { Id = i }).First();
} }
[Benchmark(Description = "Mapping Cache (dynamic)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Mapping Cache (dynamic)")]
public dynamic MappingCacheDynamic() public dynamic MappingCacheDynamic()
{ {
Step(); Step();
...@@ -45,14 +45,14 @@ public dynamic MappingCacheDynamic() ...@@ -45,14 +45,14 @@ public dynamic MappingCacheDynamic()
.Execute(_db, new { Id = i }).First(); .Execute(_db, new { Id = i }).First();
} }
[Benchmark(Description = "Mapping Static", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Mapping 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)", OperationsPerInvoke = Iterations)] [Benchmark(Description = "Mapping Static (dynamic)")]
public dynamic MappingStaticDynamic() public dynamic MappingStaticDynamic()
{ {
Step(); Step();
......
...@@ -46,10 +46,12 @@ public Config() ...@@ -46,10 +46,12 @@ public Config()
Add(new ORMColum()); Add(new ORMColum());
Add(new ReturnColum()); Add(new ReturnColum());
Add(Job.Default Add(Job.Default
.WithUnrollFactor(BenchmarkBase.Iterations)
//.WithIterationTime(new TimeInterval(500, TimeUnit.Millisecond))
.WithLaunchCount(1) .WithLaunchCount(1)
.WithIterationTime(new TimeInterval(500, TimeUnit.Millisecond)) .WithWarmupCount(0)
.WithWarmupCount(3) .WithTargetCount(5)
.WithTargetCount(3) .WithRemoveOutliers(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