Skip to content

Commit 82a0059

Browse files
maksimkarpenkoNickCraver
authored andcommitted
Add the eXpress Persistent Objects (XPO) benchmark (#1131)
1 parent ec19442 commit 82a0059

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using BenchmarkDotNet.Attributes;
2+
3+
using System;
4+
using System.Linq;
5+
using System.ComponentModel;
6+
using DevExpress.Xpo;
7+
using DevExpress.Data.Filtering;
8+
9+
namespace Dapper.Tests.Performance
10+
{
11+
[Description("DevExpress.XPO")]
12+
public class XpoBenchmarks : BenchmarkBase
13+
{
14+
public UnitOfWork _session;
15+
16+
[GlobalSetup]
17+
public void Setup()
18+
{
19+
BaseSetup();
20+
IDataLayer dataLayer = XpoDefault.GetDataLayer(_connection, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
21+
dataLayer.Dictionary.GetDataStoreSchema(typeof(Xpo.Post));
22+
_session = new UnitOfWork(dataLayer, dataLayer);
23+
_session.IdentityMapBehavior = IdentityMapBehavior.Strong;
24+
_session.TypesManager.EnsureIsTypedObjectValid();
25+
}
26+
27+
[GlobalCleanup]
28+
public void Cleanup()
29+
{
30+
_session.Dispose();
31+
}
32+
33+
[Benchmark(Description = "GetObjectByKey<T>")]
34+
public Xpo.Post GetObjectByKey()
35+
{
36+
Step();
37+
return _session.GetObjectByKey<Xpo.Post>(i, true);
38+
}
39+
40+
[Benchmark(Description = "FindObject<T>")]
41+
public Xpo.Post FindObject()
42+
{
43+
Step();
44+
CriteriaOperator _findCriteria = new BinaryOperator()
45+
{
46+
OperatorType = BinaryOperatorType.Equal,
47+
LeftOperand = new OperandProperty("Id"),
48+
RightOperand = new ConstantValue(i)
49+
};
50+
return _session.FindObject<Xpo.Post>(_findCriteria);
51+
}
52+
53+
[Benchmark(Description = "Query<T>")]
54+
public Xpo.Post Query()
55+
{
56+
Step();
57+
return _session.Query<Xpo.Post>().First(p => p.Id == i);
58+
}
59+
}
60+
}

Dapper.Tests.Performance/Dapper.Tests.Performance.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="Dashing.Weaver" Version="2.0.7" />
1717
<PackageReference Include="Belgrade.Sql.Client" Version="1.1.4" />
1818
<PackageReference Include="BenchmarkDotNet" Version="0.11.1" />
19+
<PackageReference Include="DevExpress.Xpo" Version="18.1.6" />
1920
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
2021
<PackageReference Include="EntityFramework" Version="6.2.0" />
2122
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="6.3.0" />

Dapper.Tests.Performance/LegacyTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
using Dashing;
2525
using Microsoft.EntityFrameworkCore;
2626
using Belgrade.SqlClient;
27+
using DevExpress.Xpo;
28+
using Dapper.Tests.Performance.Xpo;
29+
using DevExpress.Data.Filtering;
2730

2831
namespace Dapper.Tests.Performance
2932
{
@@ -386,6 +389,30 @@ public async Task RunAsync(int iterations)
386389
#endif
387390
}, "Hand Coded");
388391

392+
// DevExpress.XPO
393+
Try(() =>
394+
{
395+
IDataLayer dataLayer = XpoDefault.GetDataLayer(connection, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
396+
dataLayer.Dictionary.GetDataStoreSchema(typeof(Xpo.Post));
397+
UnitOfWork session = new UnitOfWork(dataLayer, dataLayer);
398+
session.IdentityMapBehavior = IdentityMapBehavior.Strong;
399+
session.TypesManager.EnsureIsTypedObjectValid();
400+
401+
tests.Add(id => session.Query<Xpo.Post>().First(p => p.Id == id), "DevExpress.XPO: Query<T>");
402+
tests.Add(id => session.GetObjectByKey<Xpo.Post>(id, true), "DevExpress.XPO: GetObjectByKey<T>");
403+
tests.Add(id =>
404+
{
405+
CriteriaOperator findCriteria = new BinaryOperator()
406+
{
407+
OperatorType = BinaryOperatorType.Equal,
408+
LeftOperand = new OperandProperty("Id"),
409+
RightOperand = new ConstantValue(id)
410+
};
411+
session.FindObject<Xpo.Post>(findCriteria);
412+
}, "DevExpress.XPO: FindObject<T>");
413+
414+
}, "DevExpress.XPO");
415+
389416
// Subsonic isn't maintained anymore - doesn't import correctly
390417
//Try(() =>
391418
// {

Dapper.Tests.Performance/XPO/Post.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using DevExpress.Xpo;
3+
4+
namespace Dapper.Tests.Performance.Xpo
5+
{
6+
[Persistent("Posts")]
7+
public class Post : XPLiteObject
8+
{
9+
[Key(false)]
10+
public int Id { get; set; }
11+
public string Text { get; set; }
12+
public DateTime CreationDate { get; set; }
13+
public DateTime LastChangeDate { get; set; }
14+
public int? Counter1 { get; set; }
15+
public int? Counter2 { get; set; }
16+
public int? Counter3 { get; set; }
17+
public int? Counter4 { get; set; }
18+
public int? Counter5 { get; set; }
19+
public int? Counter6 { get; set; }
20+
public int? Counter7 { get; set; }
21+
public int? Counter8 { get; set; }
22+
public int? Counter9 { get; set; }
23+
public Post(Session session) : base(session) { }
24+
}
25+
}

0 commit comments

Comments
 (0)