forked from DapperLib/Dapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmarks.Linq2Sql.cs
More file actions
43 lines (38 loc) · 1.27 KB
/
Benchmarks.Linq2Sql.cs
File metadata and controls
43 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using BenchmarkDotNet.Attributes;
using Dapper.Tests.Performance.Linq2Sql;
using System;
using System.Data.Linq;
using System.Linq;
namespace Dapper.Tests.Performance
{
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 = "Normal")]
public Linq2Sql.Post Normal()
{
Step();
return Linq2SqlContext.Posts.First(p => p.Id == i);
}
[Benchmark(Description = "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();
}
}
}