Files
Dapper/Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs
T
Nick Craver 1481c4d379 Tooling and project updates (#1333)
This is a branch cleaning up old `#if` clauses, `.csproj` bits, Linux build compatibility, and a few other tid-bits (broken out by commit).

In general: we're on 3.0 tooling and all previous cruft has been removed.
2019-09-26 19:47:55 -04:00

49 lines
1.4 KiB
C#

#if NET4X
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));
[GlobalSetup]
public void Setup()
{
BaseSetup();
Linq2SqlContext = new DataClassesDataContext(_connection);
}
[Benchmark(Description = "First")]
public Linq2Sql.Post First()
{
Step();
return Linq2SqlContext.Posts.First(p => p.Id == i);
}
[Benchmark(Description = "First (Compiled)")]
public Linq2Sql.Post Compiled()
{
Step();
return compiledQuery(Linq2SqlContext, i);
}
[Benchmark(Description = "ExecuteQuery")]
public Post ExecuteQuery()
{
Step();
return Linq2SqlContext.ExecuteQuery<Post>("select * from Posts where Id = {0}", i).First();
}
}
}
#endif