Commit 6fa2b678 authored by mgravell's avatar mgravell

standardise perf tests on First(); measure buffered and unbuffered (dapper...

standardise perf tests on First(); measure buffered and unbuffered (dapper only); introduce * splits, useful for creating tuples of primitives
parent 6f28e5c8
......@@ -344,7 +344,7 @@ class DontMap {}
for (pos = current + 1; pos < reader.FieldCount; pos++)
{
// some people like ID some id ... assuming case insensitive splits for now
if (string.Equals(reader.GetName(pos), currentSplit, StringComparison.InvariantCultureIgnoreCase))
if (splitOn=="*" || string.Equals(reader.GetName(pos), currentSplit, StringComparison.InvariantCultureIgnoreCase))
{
break;
}
......@@ -470,7 +470,7 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
{
return GetClassDeserializer<T>(reader, startBound, length, returnNullIfFirstMissing);
}
return GetStructDeserializer<T>();
return GetStructDeserializer<T>(startBound);
}
#if !CSHARP30
......@@ -725,11 +725,11 @@ private static int ExecuteCommand(IDbConnection cnn, IDbTransaction tranaction,
}
}
private static Func<IDataReader, T> GetStructDeserializer<T>()
private static Func<IDataReader, T> GetStructDeserializer<T>(int index)
{
return r =>
{
var val = r.GetValue(0);
var val = r.GetValue(index);
if (val == DBNull.Value)
{
val = null;
......
......@@ -95,7 +95,7 @@ public void Run(int iterations)
tests.Add(id => compiledGetPost(l2scontext2,id), "Linq 2 SQL Compiled");
var l2scontext3 = GetL2SContext();
tests.Add(id => l2scontext3.ExecuteQuery<Post>("select * from Posts where Id = {0}", id).ToList(), "Linq 2 SQL ExecuteQuery");
tests.Add(id => l2scontext3.ExecuteQuery<Post>("select * from Posts where Id = {0}", id).First(), "Linq 2 SQL ExecuteQuery");
var entityContext = new EntityFramework.tempdbEntities1();
entityContext.Connection.Open();
......@@ -103,7 +103,7 @@ public void Run(int iterations)
var entityContext2 = new EntityFramework.tempdbEntities1();
entityContext2.Connection.Open();
tests.Add(id => entityContext2.ExecuteStoreQuery<Post>("select * from Posts where Id = {0}", id).ToList(), "Entity framework ExecuteStoreQuery");
tests.Add(id => entityContext2.ExecuteStoreQuery<Post>("select * from Posts where Id = {0}", id).First(), "Entity framework ExecuteStoreQuery");
var entityContext3 = new EntityFramework.tempdbEntities1();
entityContext3.Connection.Open();
......@@ -119,14 +119,18 @@ public void Run(int iterations)
tests.Add(id => entityContext.Posts.First(p => p.Id == id), "Entity framework No Tracking");
var mapperConnection = Program.GetOpenConnection();
tests.Add(id => mapperConnection.Query<Post>("select * from Posts where Id = @Id", new { Id = id }).ToList(), "Mapper Query");
tests.Add(id => mapperConnection.Query<Post>("select * from Posts where Id = @Id", new { Id = id }, buffered: true).First(), "Mapper Query (buffered)");
tests.Add(id => mapperConnection.Query<Post>("select * from Posts where Id = @Id", new { Id = id }, buffered: false).First(), "Mapper Query (non-buffered)");
var mapperConnection2 = Program.GetOpenConnection();
tests.Add(id => mapperConnection2.Query("select * from Posts where Id = @Id", new { Id = id }).ToList(), "Dynamic Mapper Query");
tests.Add(id => mapperConnection2.Query("select * from Posts where Id = @Id", new { Id = id }, buffered: true).First(), "Dynamic Mapper Query (buffered)");
tests.Add(id => mapperConnection2.Query("select * from Posts where Id = @Id", new { Id = id }, buffered: true).First(), "Dynamic Mapper Query (non-buffered)");
var massiveModel = new DynamicModel(Program.connectionString);
var massiveConnection = Program.GetOpenConnection();
tests.Add(id => massiveModel.Query("select * from Posts where Id = @0", massiveConnection, id).ToList(), "Dynamic Massive ORM Query");
tests.Add(id => massiveModel.Query("select * from Posts where Id = @0", massiveConnection, id).First(), "Dynamic Massive ORM Query");
// PetaPoco test with all default options
var petapoco = new PetaPoco.Database(Program.connectionString, "System.Data.SqlClient");
......@@ -168,7 +172,7 @@ public void Run(int iterations)
var nhSession4 = NHibernateHelper.OpenSession();
tests.Add(id => nhSession4
.Query<Post>()
.Where(p => p.Id == id).ToList(), "NHibernate LINQ");
.Where(p => p.Id == id).First(), "NHibernate LINQ");
// bltoolkit
var db1 = new DbManager(Program.GetOpenConnection());
......
......@@ -39,11 +39,12 @@ public static SqlConnection GetOpenConnection()
static void RunPerformanceTests()
{
var test = new PerformanceTests();
Console.WriteLine("Running 500 iterations that load up a post entity");
test.Run(500);
const int iterations = 500;
Console.WriteLine("Running {0} iterations that load up a post entity", iterations);
test.Run(iterations);
}
static void Main(string[] args)
static void Main()
{
#if DEBUG
......@@ -91,7 +92,7 @@ Counter9 int
set @i = 0
while @i < 5000
while @i <= 5001
begin
insert Posts ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000), GETDATE(), GETDATE())
......
......@@ -72,6 +72,12 @@ public void PassInIntArray()
.IsSequenceEqualTo(new[] { 1, 2, 3 });
}
public void TestReadMultipleIntegersWithSplitOnAny()
{
connection.Query<int,int,int,Tuple<int,int,int>>(
"select 1,2,3 union all select 4,5,6", Tuple.Create, splitOn: "*")
.IsSequenceEqualTo(new[] {Tuple.Create(1,2,3), Tuple.Create(4,5,6)});
}
public void TestDoubleParam()
{
......
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