mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-19 06:31:49 +08:00
6ab170c160
* initial net5.0 tweaks; also fix current IDE warnings * lib updates and fixes * more cleanup * fix snafu * skip locals init * disable xunit shadow copy in tests * test records * explore scenario that currently works re #1571
63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
using BenchmarkDotNet.Attributes;
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.ComponentModel;
|
|
using DevExpress.Xpo;
|
|
using DevExpress.Data.Filtering;
|
|
|
|
namespace Dapper.Tests.Performance
|
|
{
|
|
[Description("DevExpress.XPO")]
|
|
public class XpoBenchmarks : BenchmarkBase
|
|
{
|
|
public UnitOfWork _session;
|
|
|
|
[GlobalSetup]
|
|
public void Setup()
|
|
{
|
|
BaseSetup();
|
|
IDataLayer dataLayer = XpoDefault.GetDataLayer(_connection, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
|
|
dataLayer.Dictionary.GetDataStoreSchema(typeof(Xpo.Post));
|
|
_session = new UnitOfWork(dataLayer, dataLayer)
|
|
{
|
|
IdentityMapBehavior = IdentityMapBehavior.Strong
|
|
};
|
|
_session.TypesManager.EnsureIsTypedObjectValid();
|
|
}
|
|
|
|
[GlobalCleanup]
|
|
public void Cleanup()
|
|
{
|
|
_session.Dispose();
|
|
}
|
|
|
|
[Benchmark(Description = "GetObjectByKey<T>")]
|
|
public Xpo.Post GetObjectByKey()
|
|
{
|
|
Step();
|
|
return _session.GetObjectByKey<Xpo.Post>(i, true);
|
|
}
|
|
|
|
[Benchmark(Description = "FindObject<T>")]
|
|
public Xpo.Post FindObject()
|
|
{
|
|
Step();
|
|
CriteriaOperator _findCriteria = new BinaryOperator()
|
|
{
|
|
OperatorType = BinaryOperatorType.Equal,
|
|
LeftOperand = new OperandProperty("Id"),
|
|
RightOperand = new ConstantValue(i)
|
|
};
|
|
return _session.FindObject<Xpo.Post>(_findCriteria);
|
|
}
|
|
|
|
[Benchmark(Description = "Query<T>")]
|
|
public Xpo.Post Query()
|
|
{
|
|
Step();
|
|
return _session.Query<Xpo.Post>().First(p => p.Id == i);
|
|
}
|
|
}
|
|
}
|