My favorites | Sign in
Project Home Downloads Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Copyright (C) 2009-2010 ORMBattle.NET.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexis Kochetov
// Created: 2009.07.31

using System;
using System.Data.Linq;
using System.Linq;
using NUnit.Framework;
using Linq2SqlModel;

namespace OrmBattle.Tests.Performance
{
[Serializable]
public class Linq2SqlTest : PerformanceTestBase
{
private PerformanceTestDataContext _db;

public override string ToolName
{
get { return "LINQ to SQL"; }
}

public override string ShortToolName
{
get { return "L2S"; }
}

protected override void Setup()
{
using (var dataContext = new PerformanceTestDataContext()) {
dataContext.Connection.Open();
using (dataContext.Transaction = dataContext.Connection.BeginTransaction()) {
dataContext.Simplests.DeleteAllOnSubmit(dataContext.Simplests);
dataContext.SubmitChanges();
dataContext.Transaction.Commit();
}
}
}

protected override void TearDown()
{
using (var dataContext = new PerformanceTestDataContext()) {
dataContext.Connection.Open();
using (dataContext.Transaction = dataContext.Connection.BeginTransaction()) {
dataContext.Simplests.DeleteAllOnSubmit(dataContext.Simplests);
dataContext.SubmitChanges();
dataContext.Transaction.Commit();
}
}
}

protected override void OpenSession()
{
_db = new PerformanceTestDataContext();
_db.Connection.Open();
}

protected override void CloseSession()
{
_db.Dispose();
}

protected override void InsertMultipleTest(int count)
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
for (var i = 0; i < count; i++) {
var s = new Simplest {Id = i, Value = i};
_db.Simplests.InsertOnSubmit(s);
}

_db.SubmitChanges();
_db.Transaction.Commit();
}

InstanceCount = count;
}

protected override void UpdateMultipleTest()
{
var sum = (long) InstanceCount * (InstanceCount - 1) / 2;

using (_db.Transaction = _db.Connection.BeginTransaction()) {
foreach (var s in _db.Simplests) {
s.Value++;
sum -= s.Id;
}

_db.SubmitChanges();
_db.Transaction.Commit();
}

Assert.AreEqual(0, sum);
}

protected override void DeleteMultipleTest()
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
_db.Simplests.DeleteAllOnSubmit(_db.Simplests);
_db.SubmitChanges();
_db.Transaction.Commit();
}
}

protected override void InsertSingleTest(int count)
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
for (var i = 0; i < count; i++) {
var s = new Simplest {Id = i, Value = i};
_db.Simplests.InsertOnSubmit(s);
_db.SubmitChanges();
}

_db.Transaction.Commit();
}

InstanceCount = count;
}

protected override void UpdateSingleTest()
{
var sum = (long) InstanceCount * (InstanceCount - 1) / 2;

using (_db.Transaction = _db.Connection.BeginTransaction()) {
foreach (var s in _db.Simplests) {
s.Value++;
sum -= s.Id;
_db.SubmitChanges();
}

_db.Transaction.Commit();
}

Assert.AreEqual(0, sum);
}

protected override void DeleteSingleTest()
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
foreach (var s in _db.Simplests) {
_db.Simplests.DeleteOnSubmit(s);
_db.SubmitChanges();
}

_db.Transaction.Commit();
}
}

private static readonly Func<PerformanceTestDataContext, long, Simplest> _compiledFetcher =
CompiledQuery.Compile((PerformanceTestDataContext context, long id) =>
context.Simplests.SingleOrDefault(o => o.Id==id));

protected override void FetchTest(int count)
{
var sum = (long) count * (count - 1) / 2;

using (_db.Transaction = _db.Connection.BeginTransaction()) {
for (var i = 0; i < count; i++) {
var id = (long) i % InstanceCount;
var s = _compiledFetcher(_db, id);
sum -= s.Id;
}

_db.Transaction.Commit();
}

if (count <= InstanceCount)
Assert.AreEqual(0, sum);
}

protected override void LinqQueryTest(int count)
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
for (var i = 0; i < count; i++) {
var id = (long) i % InstanceCount;
var result = _db.Simplests.Where(o => o.Id==id);
foreach (var o in result) {
// Doing nothing, just enumerate
}
}

_db.Transaction.Commit();
}
}

private static readonly Func<PerformanceTestDataContext, long, IQueryable<Simplest>> _compiledQuery =
CompiledQuery.Compile((PerformanceTestDataContext context, long id) =>
context.Simplests.Where(o => o.Id==id));

protected override void CompiledLinqQueryTest(int count)
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
for (var i = 0; i < count; i++) {
var id = (long) i % InstanceCount;
foreach (var o in _compiledQuery(_db, id)) {
// Doing nothing, just enumerate
}
}

_db.Transaction.Commit();
}
}

protected override void NativeQueryTest(int count)
{
throw new NotSupportedException();
}

protected override void LinqMaterializeTest(int count)
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
var i = 0;
while (i < count)
foreach (var o in _db.Simplests.Where(s => s.Id > 0)) {
if (++i >= count)
break;
}

_db.Transaction.Commit();
}
}

protected override void NativeMaterializeTest(int count)
{
throw new NotSupportedException();
}

private static readonly Func<PerformanceTestDataContext, long, int, IQueryable<Simplest>> _pageQuery = CompiledQuery.Compile(
(PerformanceTestDataContext context, long id, int pgSize) =>
context.Simplests.Where(o => o.Id >= id).Take(pgSize));

protected override void LinqQueryPageTest(int count, int pageSize)
{
using (_db.Transaction = _db.Connection.BeginTransaction()) {
for (var i = 0; i < count; i++) {
var id = (i * pageSize) % InstanceCount;
foreach (var o in _pageQuery(_db, id, pageSize)) {
// Doing nothing, just enumerate
}
}

_db.Transaction.Commit();
}
}
}
}

Change log

f0f7d2b3710a by Alex Yakunin on Aug 4, 2010   Diff
Code formatting; ref. to
JetBrains.Annotations is removed.
Go to: 

Older revisions

c6412f95a8d3 by Alex Yakunin on Jun 10, 2010   Diff
Project is upgraded to .NET 4.0.
76e51cd2728f by alex.yakunin on Oct 21, 2009   Diff
1. -ppc:X argument is added (~
"Performance: Pass Count")
2. Fetch test for L2S now uses
compiled query.
3. "Linq2Sql" -> "LINQ to SQL" (please
...
6fd5fd4eda13 by alex.yakunin on Oct 19, 2009   Diff
- Test suite became fully independent
of any third-party libraries. Just
checkout and build it.
- DataObjects.Net is updated to the
latest version (v4.1 RC).
All revisions of this file

File info

Size: 7025 bytes, 247 lines
Powered by Google Project Hosting