Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Update for SqlFu benchmark to properly use Insight.Database
using System;
using System.Data;
using System.Data.SqlClient;
using CavemanTools.Testing;
using Insight.Database;
using Tests;
using System.Linq;
using CavemanTools.Model;
namespace Benchmark.Tests
{
public class InsightDbTests:PerformanceTests
{
private SqlConnection _cnx;
private const string Name = "InsightDatabase";
public InsightDbTests()
{
_cnx = Config.GetOpenConnection();
}
public override void FetchSingleEntity(BenchmarksContainer bc)
{
bc.Add(d=>
{
_cnx.QuerySql<sfPosts>("select * from sfPosts where id=@id", new {id = 5}).FirstOrDefault();
},Name);
}
public override void FetchSingleDynamicEntity(BenchmarksContainer bc)
{
bc.Add(d =>
{
_cnx.QuerySql("select * from sfPosts where id=@id", new { id = 5 }).FirstOrDefault();
}, Name);
}
public override void QueryTop10(BenchmarksContainer bc)
{
bc.Add(d =>
{
_cnx.QuerySql<sfPosts>("select top 10 * from sfPosts where id>@id", new { id = 5 }).ToArray();
}, Name);
}
public override void QueryTop10Dynamic(BenchmarksContainer bc)
{
bc.Add(d =>
{
_cnx.QuerySql("select top 10 * from sfPosts where id>@id", new { id = 5 }).ToArray();
}, Name);
}
public override void PagedQuery_Skip0_Take10(BenchmarksContainer bc)
{
bc.Add(d => {
_cnx.QuerySql<sfPosts>("select * from sfposts order by id offset @skip rows fetch first @take rows only", new { skip = 0, take = 5 });
}, Name);
}
public override void ExecuteScalar(BenchmarksContainer bc)
{
bc.Add(d =>
{
_cnx.ExecuteScalarSql<int>("select authorid from sfPosts where id=@id", new { id = 5 });
}, Name);
}
public override void MultiPocoMapping(BenchmarksContainer bc)
{
bc.Add(d => {
_cnx.QuerySql<PostViewModel, IdName>("select *, Id, title as Name from sfposts where id=@id", new { id = 5 });
}, Name);
}
public override void Inserts(BenchmarksContainer bc)
{
var p = sfPosts.Create();
bc.Add(id =>
{
_cnx.InsertSql("insert into sfposts (authorid, title, isActive, createdon) values (@authorid, @title, @isactive, @createdon)", p);
}, Name);
}
public override void Updates(BenchmarksContainer bc)
{
var p = new sfPosts();
p.Id = 3;
p.Title = "updated";
bc.Add(id =>
{
_cnx.ExecuteSql("update sfposts set title = @title where id = @id", p);
}, Name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment