Skip to content

Commit

Permalink
Try and use BenchmarkDotNet correctly
Browse files Browse the repository at this point in the history
OperationsPerInvoke is an informational, not instructional property.
What we actually want is the UnrollFactor. Moved into the job definition
to simplify things.
  • Loading branch information
NickCraver committed May 14, 2017
1 parent f39cff3 commit fb44338
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/Benchmarks.Belgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Setup()
_mapper = new QueryMapper(ConnectionString);
}

[Benchmark(Description = "ExecuteReader", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "ExecuteReader")]
public async Task ExecuteReader()
{
Step();
Expand Down
14 changes: 7 additions & 7 deletions Dapper.Tests.Performance/Benchmarks.Dapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,46 @@ public void Setup()
BaseSetup();
}

[Benchmark(Description = "Query<T> (buffered)", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Query<T> (buffered)")]
public Post QueryBuffered()
{
Step();
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()
{
Step();
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()
{
Step();
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()
{
Step();
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()
{
Step();
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()
{
Step();
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()
{
Step();
Expand Down
6 changes: 3 additions & 3 deletions Dapper.Tests.Performance/Benchmarks.EntityFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public void Setup()
Context = new EntityFramework.EFContext(_connection);
}

[Benchmark(Description = "Normal", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Normal")]
public Post Normal()
{
Step();
return Context.Posts.First(p => p.Id == i);
}

[Benchmark(Description = "SqlQuery", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "SqlQuery")]
public Post SqlQuery()
{
Step();
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()
{
Step();
Expand Down
4 changes: 2 additions & 2 deletions Dapper.Tests.Performance/Benchmarks.HandCoded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Setup()
#endif
}

[Benchmark(Description = "SqlCommand", OperationsPerInvoke = Iterations, Baseline = true)]
[Benchmark(Description = "SqlCommand", Baseline = true)]
public Post SqlCommand()
{
Step();
Expand Down Expand Up @@ -75,7 +75,7 @@ public Post SqlCommand()
}
}

[Benchmark(Description = "DataTable", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "DataTable")]
public dynamic DataTableDynamic()
{
Step();
Expand Down
6 changes: 3 additions & 3 deletions Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public void Setup()
Linq2SqlContext = new DataClassesDataContext(_connection);
}

[Benchmark(Description = "Normal", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Normal")]
public Linq2Sql.Post Normal()
{
Step();
return Linq2SqlContext.Posts.First(p => p.Id == i);
}

[Benchmark(Description = "Compiled", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Compiled")]
public Linq2Sql.Post Compiled()
{
Step();
return compiledQuery(Linq2SqlContext, i);
}

[Benchmark(Description = "ExecuteQuery", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "ExecuteQuery")]
public Post ExecuteQuery()
{
Step();
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/Benchmarks.Massive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Setup()
_model = new DynamicModel(ConnectionString);
}

[Benchmark(Description = "Query (dynamic)", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Query (dynamic)")]
public dynamic QueryDynamic()
{
Step();
Expand Down
10 changes: 5 additions & 5 deletions Dapper.Tests.Performance/Benchmarks.NHibernate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Setup()
_get = NHibernateHelper.OpenSession();
}

[Benchmark(Description = "SQL", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "SQL")]
public Post SQL()
{
Step();
Expand All @@ -34,7 +34,7 @@ public Post SQL()
.List<Post>()[0];
}

[Benchmark(Description = "HQL", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "HQL")]
public Post HQL()
{
Step();
Expand All @@ -43,7 +43,7 @@ public Post HQL()
.List<Post>()[0];
}

[Benchmark(Description = "Criteria", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Criteria")]
public Post Criteria()
{
Step();
Expand All @@ -52,14 +52,14 @@ public Post Criteria()
.List<Post>()[0];
}

[Benchmark(Description = "LINQ", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "LINQ")]
public Post LINQ()
{
Step();
return _linq.Query<Post>().First(p => p.Id == i);
}

[Benchmark(Description = "Get<T>", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Get<T>")]
public Post Get()
{
Step();
Expand Down
4 changes: 2 additions & 2 deletions Dapper.Tests.Performance/Benchmarks.PetaPoco.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public void Setup()
_dbFast.ForceDateTimesToUtc = false;
}

[Benchmark(Description = "Fetch<Post>", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Fetch<Post>")]
public Post Fetch()
{
Step();
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()
{
Step();
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/Benchmarks.ServiceStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Setup()
_db = dbFactory.Open();
}

[Benchmark(Description = "SingleById", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "SingleById")]
public Post Query()
{
Step();
Expand Down
2 changes: 1 addition & 1 deletion Dapper.Tests.Performance/Benchmarks.Soma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Setup()
_sdb = Simple.Data.Database.OpenConnection(ConnectionString);
}

[Benchmark(Description = "FindById", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "FindById")]
public dynamic QueryDynamic()
{
Step();
Expand Down
8 changes: 4 additions & 4 deletions Dapper.Tests.Performance/Benchmarks.Susanoo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Setup()
_db = new DatabaseManager(_connection);
}

[Benchmark(Description = "Mapping Cache", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Mapping Cache")]
public Post MappingCache()
{
Step();
Expand All @@ -35,7 +35,7 @@ public Post MappingCache()
.Execute(_db, new { Id = i }).First();
}

[Benchmark(Description = "Mapping Cache (dynamic)", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Mapping Cache (dynamic)")]
public dynamic MappingCacheDynamic()
{
Step();
Expand All @@ -45,14 +45,14 @@ public dynamic MappingCacheDynamic()
.Execute(_db, new { Id = i }).First();
}

[Benchmark(Description = "Mapping Static", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Mapping Static")]
public Post MappingStatic()
{
Step();
return _cmd.Execute(_db, new { Id = i }).First();
}

[Benchmark(Description = "Mapping Static (dynamic)", OperationsPerInvoke = Iterations)]
[Benchmark(Description = "Mapping Static (dynamic)")]
public dynamic MappingStaticDynamic()
{
Step();
Expand Down
8 changes: 5 additions & 3 deletions Dapper.Tests.Performance/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public Config()
Add(new ORMColum());
Add(new ReturnColum());
Add(Job.Default
.WithUnrollFactor(BenchmarkBase.Iterations)
//.WithIterationTime(new TimeInterval(500, TimeUnit.Millisecond))
.WithLaunchCount(1)
.WithIterationTime(new TimeInterval(500, TimeUnit.Millisecond))
.WithWarmupCount(3)
.WithTargetCount(3)
.WithWarmupCount(0)
.WithTargetCount(5)
.WithRemoveOutliers(true)
);
}
}
Expand Down

0 comments on commit fb44338

Please sign in to comment.