Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 5232fe1

Browse files
committed
Update Perf Tests with AdventureWorks test
more optimizations
1 parent 349f4b3 commit 5232fe1

File tree

1 file changed

+128
-49
lines changed

1 file changed

+128
-49
lines changed

tests/ServiceStack.OrmLite.Tests/UseCase/PostPerfTests.cs

Lines changed: 128 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Data;
34
using System.Diagnostics;
45
using System.Linq;
56
using System.Reflection;
67
using NUnit.Framework;
8+
using ServiceStack.DataAnnotations;
79
using ServiceStack.OrmLite.Dapper;
810

911
namespace ServiceStack.OrmLite.Tests.UseCase
@@ -26,7 +28,7 @@ class Post
2628

2729
}
2830

29-
[Ignore, Explicit("Integration Test")]
31+
[NUnit.Framework.Ignore, Explicit("Integration Test")]
3032
public class PostPerfTests : OrmLiteTestBase
3133
{
3234
public PostPerfTests()
@@ -82,54 +84,6 @@ insert Post ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000),
8284
cmd.ExecuteNonQuery();
8385
}
8486
}
85-
86-
class Test
87-
{
88-
public static Test Create(Action<int> iteration, string name)
89-
{
90-
return new Test { Iteration = iteration, Name = name };
91-
}
92-
93-
public Action<int> Iteration { get; set; }
94-
public string Name { get; set; }
95-
public Stopwatch Watch { get; set; }
96-
}
97-
98-
class Tester : List<Test>
99-
{
100-
public void Add(Action<int> iteration, string name)
101-
{
102-
Add(Test.Create(iteration, name));
103-
}
104-
105-
public void Run(int iterations)
106-
{
107-
// warmup
108-
foreach (var test in this)
109-
{
110-
test.Iteration(iterations + 1);
111-
test.Watch = new Stopwatch();
112-
test.Watch.Reset();
113-
}
114-
115-
var rand = new Random();
116-
for (int i = 1; i <= iterations; i++)
117-
{
118-
foreach (var test in this.OrderBy(ignore => rand.Next()))
119-
{
120-
test.Watch.Start();
121-
test.Iteration(i);
122-
test.Watch.Stop();
123-
}
124-
}
125-
126-
foreach (var test in this.OrderBy(t => t.Watch.ElapsedMilliseconds))
127-
{
128-
Console.WriteLine(test.Name + " took " + test.Watch.ElapsedMilliseconds + "ms");
129-
}
130-
}
131-
}
132-
13387
[Test]
13488
public void Run_single_select_Dapper()
13589
{
@@ -185,4 +139,129 @@ public void Run_multi_select_OrmLite_SqlExpression()
185139
tester.Run(50);
186140
}
187141
}
142+
143+
[NUnit.Framework.Ignore, Explicit("Integration Test")]
144+
public class AdventureWorksPerfTests : OrmLiteTestBase
145+
{
146+
private IDbConnection db;
147+
148+
public AdventureWorksPerfTests()
149+
{
150+
var dbFactory = new OrmLiteConnectionFactory(
151+
"data source=localhost;initial catalog=AdventureWorks;integrated security=SSPI;persist security info=False;packet size=4096",
152+
SqlServer2012Dialect.Provider);
153+
154+
db = dbFactory.Open();
155+
}
156+
157+
[TearDown]
158+
public void TearDown()
159+
{
160+
db.Dispose();
161+
}
162+
163+
private static string SqlSelectCommandText = @"SELECT [SalesOrderID],[RevisionNumber],[OrderDate],[DueDate],[ShipDate],[Status],[OnlineOrderFlag],[SalesOrderNumber],[PurchaseOrderNumber],[AccountNumber],[CustomerID],[SalesPersonID],[TerritoryID],[BillToAddressID],[ShipToAddressID],[ShipMethodID],[CreditCardID],[CreditCardApprovalCode],[CurrencyRateID],[SubTotal],[TaxAmt],[Freight],[TotalDue],[Comment],[rowguid],[ModifiedDate] FROM [Sales].[SalesOrderHeader]";
164+
165+
[Test]
166+
public void Select_all_SalesOrderHeader_Dapper()
167+
{
168+
db.Query<SalesOrderHeader>(SqlSelectCommandText).AsList();
169+
170+
var tester = new Tester();
171+
172+
tester.Add(id => db.Query<SalesOrderHeader>(SqlSelectCommandText).AsList(), "Dapper Query");
173+
174+
tester.Run(10);
175+
}
176+
177+
[Test]
178+
public void Select_all_SalesOrderHeader_OrmLite()
179+
{
180+
var tester = new Tester();
181+
182+
tester.Add(id => db.SqlList<SalesOrderHeader>(SqlSelectCommandText), "OrmLite Query");
183+
184+
tester.Run(10);
185+
}
186+
}
187+
188+
[Schema("Sales")]
189+
public class SalesOrderHeader
190+
{
191+
public string AccountNumber { get; set; }
192+
public string Comment { get; set; }
193+
public string CreditCardApprovalCode { get; set; }
194+
public DateTime DueDate { get; set; }
195+
public decimal Freight { get; set; }
196+
public DateTime ModifiedDate { get; set; }
197+
public bool OnlineOrderFlag { get; set; }
198+
public DateTime OrderDate { get; set; }
199+
public string PurchaseOrderNumber { get; set; }
200+
public byte RevisionNumber { get; set; }
201+
public Guid Rowguid { get; set; }
202+
public int SalesOrderId { get; set; }
203+
public string SalesOrderNumber { get; set; }
204+
public DateTime? ShipDate { get; set; }
205+
public byte Status { get; set; }
206+
public decimal SubTotal { get; set; }
207+
public decimal TaxAmt { get; set; }
208+
public decimal TotalDue { get; set; }
209+
210+
public int CustomerID { get; set; }
211+
public int? SalesPersonID { get; set; }
212+
public int? TerritoryID { get; set; }
213+
public int BillToAddressID { get; set; }
214+
public int ShipToAddressID { get; set; }
215+
public int ShipMethodID { get; set; }
216+
public int? CreditCardID { get; set; }
217+
public int? CurrencyRateID { get; set; }
218+
}
219+
220+
class Test
221+
{
222+
public static Test Create(Action<int> iteration, string name)
223+
{
224+
return new Test { Iteration = iteration, Name = name };
225+
}
226+
227+
public Action<int> Iteration { get; set; }
228+
public string Name { get; set; }
229+
public Stopwatch Watch { get; set; }
230+
}
231+
232+
class Tester : List<Test>
233+
{
234+
public void Add(Action<int> iteration, string name)
235+
{
236+
Add(Test.Create(iteration, name));
237+
}
238+
239+
public void Run(int iterations)
240+
{
241+
// warmup
242+
foreach (var test in this)
243+
{
244+
test.Iteration(iterations + 1);
245+
test.Watch = new Stopwatch();
246+
test.Watch.Reset();
247+
}
248+
249+
var rand = new Random();
250+
for (int i = 1; i <= iterations; i++)
251+
{
252+
foreach (var test in this.OrderBy(ignore => rand.Next()))
253+
{
254+
test.Watch.Start();
255+
test.Iteration(i);
256+
test.Watch.Stop();
257+
}
258+
}
259+
260+
foreach (var test in this.OrderBy(t => t.Watch.ElapsedMilliseconds))
261+
{
262+
Console.WriteLine(test.Name + " took " + test.Watch.ElapsedMilliseconds + "ms");
263+
}
264+
}
265+
}
266+
188267
}

0 commit comments

Comments
 (0)