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
// 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.Objects;
using OrmBattle.EFModel;
using NUnit.Framework;
using System.Linq;

namespace OrmBattle.Tests.Performance
{
[Serializable]
public class EFTest : PerformanceTestBase
{
private PerformanceTestEntities context;

public override string ToolName
{
get { return "ADO.NET Entity Framework"; }
}
public override string ShortToolName
{
get { return "EF"; }
}

protected override void Setup()
{
using (var dataContext = new PerformanceTestEntities()) {
dataContext.Connection.Open();
using (var transaction = dataContext.Connection.BeginTransaction()) {
foreach (var s in dataContext.Simplests)
dataContext.DeleteObject(s);
dataContext.SaveChanges(true);
transaction.Commit();
}
}
}

protected override void TearDown()
{
using (var dataContext = new PerformanceTestEntities()) {
dataContext.Connection.Open();
using (var transaction = dataContext.Connection.BeginTransaction()) {
foreach (var s in dataContext.Simplests)
dataContext.DeleteObject(s);
dataContext.SaveChanges(true);
transaction.Commit();
}
}
}

protected override void OpenSession()
{
context = new PerformanceTestEntities();
context.Connection.Open();
}

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

protected override void InsertMultipleTest(int count)
{
using (var transaction = context.Connection.BeginTransaction()) {
for (int i = 0; i < count; i++) {
var s = Simplest.CreateSimplest(i, i);
context.AddToSimplests(s);
}
context.SaveChanges();
transaction.Commit();
}
InstanceCount = count;
}

protected override void UpdateMultipleTest()
{
long sum = (long) InstanceCount * (InstanceCount - 1) / 2;
using (var transaction = context.Connection.BeginTransaction()) {
foreach (var s in context.Simplests) {
s.Value++;
sum -= s.Id;
}
context.SaveChanges();
transaction.Commit();
}
Assert.AreEqual(0, sum);
}

protected override void DeleteMultipleTest()
{
using (var transaction = context.Connection.BeginTransaction()) {
foreach (var s in context.Simplests)
context.DeleteObject(s);
context.SaveChanges();
transaction.Commit();
}
}

protected override void InsertSingleTest(int count)
{
using (var transaction = context.Connection.BeginTransaction()) {
for (int i = 0; i < count; i++) {
var s = Simplest.CreateSimplest(i, i);
context.AddToSimplests(s);
context.SaveChanges();
}
transaction.Commit();
}
InstanceCount = count;
}

protected override void UpdateSingleTest()
{
long sum = (long) InstanceCount * (InstanceCount - 1) / 2;
using (var transaction = context.Connection.BeginTransaction()) {
foreach (var s in context.Simplests) {
s.Value++;
sum -= s.Id;
context.SaveChanges();
}
transaction.Commit();
}
Assert.AreEqual(0, sum);
}

protected override void DeleteSingleTest()
{
using (var transaction = context.Connection.BeginTransaction()) {
foreach (var s in context.Simplests) {
context.DeleteObject(s);
context.SaveChanges();
}
transaction.Commit();
}
}

protected override void FetchTest(int count)
{
long sum = (long) count * (count - 1) / 2;
using (var transaction = context.Connection.BeginTransaction()) {
for (int i = 0; i < count; i++) {
var s = Simplest.GetById(context, ((long) i) % InstanceCount);
sum -= s.Id;
}
transaction.Commit();
}

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

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

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

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

protected override void NativeQueryTest(int count)
{
using (var transaction = context.Connection.BeginTransaction()) {
for (int i = 0; i < count; i++) {
var id = i % InstanceCount;
var result = context.Simplests.Where("it.Id == @id", new ObjectParameter("id", id));
foreach (var o in result) {
// Doing nothing, just enumerate
}
}
transaction.Commit();
}
}

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

protected override void NativeMaterializeTest(int count)
{
using (var transaction = context.Connection.BeginTransaction()) {
int i = 0;
while (i < count)
foreach (var o in context.Simplests) {
if (++i >= count)
break;
}
transaction.Commit();
}
}

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

protected override void LinqQueryPageTest(int count, int pageSize)
{
using (var transaction = context.Connection.BeginTransaction()) {
for (int i = 0; i < count; i++) {
var id = (i * pageSize) % InstanceCount;
foreach (var o in _pageQuery(context, id, pageSize)) {
// Doing nothing, just enumerate
}
}
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

89ab2e816435 by Alex Yakunin on Aug 4, 2010   Diff
Issue with EF Fetch test in 64-bit
Windows is fixed.
220298071f74 by Alex Yakunin on Aug 3, 2010   Diff
Fixed various formatting \ conding
convention bugs.
623f8f32d646 by Alex Yakunin on Jul 29, 2010   Diff
- .xslm with test results is updated
- minor fixes (incl. 1 failing EF
test).
All revisions of this file

File info

Size: 7361 bytes, 244 lines
Powered by Google Project Hosting