Files
Umbraco-CMS/src/Umbraco.Tests.Benchmarks/ModelToSqlExpressionHelperBenchmarks.cs

78 lines
2.8 KiB
C#
Raw Normal View History

using System;
using System.Linq.Expressions;
using BenchmarkDotNet.Attributes;
2017-05-12 14:49:44 +02:00
using Moq;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Persistence.SqlCe;
using Umbraco.Core.Models;
2019-03-29 08:30:51 +01:00
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.SqlSyntax;
Netcore: Alternate approach for MSDI refactor (#9247) * Doesn't make much sense to have Concrete on IRegister, only on IFactory * Handle FilesTreeController requires IFileSystem of type PhysicalFileSystem * Handle registration of default MediaFileSystem without using RegisterUniqueFor * Remove RegisterFor / RegisterUniqueFor from IRegister * Switch over from LightInject to wrappers around MSDI * Made mapper dependencies more explicit * Remove registration for AngularJsonMediaTypeFormatter It's dependencies aren't registered so container validation fails * Resolve lifetime issue for EnsureValidSessionId by service locating else resolve scoped in singleton * Make registration more explicit for backoffice UserManager * Make install step registrations more explicit * Disable service provider validation so site can launch Maybe this is a problem maybe not, we build about 8000 service providers so maybe everything is fine later... * Further cleanup of IFactory interface * Further cleanup of IRegister interface * Revert "Make registration more explicit for backoffice UserManager" This reverts commit 7215fe836103c597cd0873c66737a79b91ed4c49. * Resolve issue where NewInstallStep would fail to reset password for "SuperUser" Before MSDI, somehow BackOfficeIdentityOptions would be configured with token provider map from IdentityBuilder.AddDefaultTokenProviders. After switchover those config actions are lost. Subclass IdentityBuilder to ensure BackOfficeIdentityOptions doesn't miss config setup upstream. * Initialize current. * Add todo to turn container validation back on. * Migrated ScopeFileSystemsTests to integration tests Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Resolve issue where MediaFileSystem was skipping ShadowFileSystem * Attempt to fix ScopeFileSystemsTests on azure devops Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Be interesting to know what the actual full path is in pipeline. * Clarify intent of CreateMediaTest Doesn't help resolve weird UnauthorizedAccessException but it cuts so much cognitive overhead for the future. * Use ILoggerfactory rather than mock for the manually constructed file PhysicalFileSystem * Maybe resolve failing test on azure pipeline. Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2020-10-26 10:47:14 +00:00
using Umbraco.Infrastructure.Persistence.Mappers;
namespace Umbraco.Tests.Benchmarks
{
2018-03-27 16:42:52 +02:00
[MemoryDiagnoser]
public class ModelToSqlExpressionHelperBenchmarks
{
2019-04-02 13:35:01 +02:00
protected Lazy<ISqlContext> MockSqlContext()
2019-03-29 08:30:51 +01:00
{
var sqlContext = Mock.Of<ISqlContext>();
var syntax = new SqlCeSyntaxProvider();
Mock.Get(sqlContext).Setup(x => x.SqlSyntax).Returns(syntax);
2019-04-02 13:35:01 +02:00
return new Lazy<ISqlContext>(() => sqlContext);
2019-03-29 08:30:51 +01:00
}
Netcore: Alternate approach for MSDI refactor (#9247) * Doesn't make much sense to have Concrete on IRegister, only on IFactory * Handle FilesTreeController requires IFileSystem of type PhysicalFileSystem * Handle registration of default MediaFileSystem without using RegisterUniqueFor * Remove RegisterFor / RegisterUniqueFor from IRegister * Switch over from LightInject to wrappers around MSDI * Made mapper dependencies more explicit * Remove registration for AngularJsonMediaTypeFormatter It's dependencies aren't registered so container validation fails * Resolve lifetime issue for EnsureValidSessionId by service locating else resolve scoped in singleton * Make registration more explicit for backoffice UserManager * Make install step registrations more explicit * Disable service provider validation so site can launch Maybe this is a problem maybe not, we build about 8000 service providers so maybe everything is fine later... * Further cleanup of IFactory interface * Further cleanup of IRegister interface * Revert "Make registration more explicit for backoffice UserManager" This reverts commit 7215fe836103c597cd0873c66737a79b91ed4c49. * Resolve issue where NewInstallStep would fail to reset password for "SuperUser" Before MSDI, somehow BackOfficeIdentityOptions would be configured with token provider map from IdentityBuilder.AddDefaultTokenProviders. After switchover those config actions are lost. Subclass IdentityBuilder to ensure BackOfficeIdentityOptions doesn't miss config setup upstream. * Initialize current. * Add todo to turn container validation back on. * Migrated ScopeFileSystemsTests to integration tests Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Resolve issue where MediaFileSystem was skipping ShadowFileSystem * Attempt to fix ScopeFileSystemsTests on azure devops Signed-off-by: Bjarke Berg <mail@bergmania.dk> * Be interesting to know what the actual full path is in pipeline. * Clarify intent of CreateMediaTest Doesn't help resolve weird UnauthorizedAccessException but it cuts so much cognitive overhead for the future. * Use ILoggerfactory rather than mock for the manually constructed file PhysicalFileSystem * Maybe resolve failing test on azure pipeline. Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2020-10-26 10:47:14 +00:00
protected MapperConfigurationStore CreateMaps()
=> new MapperConfigurationStore();
2019-03-29 08:30:51 +01:00
public ModelToSqlExpressionHelperBenchmarks()
{
2019-03-29 08:30:51 +01:00
var contentMapper = new ContentMapper(MockSqlContext(), CreateMaps());
_cachedExpression = new CachedExpression();
2017-05-12 14:49:44 +02:00
var mapperCollection = new Mock<IMapperCollection>();
mapperCollection.Setup(x => x[It.IsAny<Type>()]).Returns(contentMapper);
_mapperCollection = mapperCollection.Object;
}
2017-07-20 11:21:28 +02:00
private readonly ISqlSyntaxProvider _syntaxProvider = new SqlCeSyntaxProvider();
private readonly CachedExpression _cachedExpression;
2017-05-12 14:49:44 +02:00
private readonly IMapperCollection _mapperCollection;
[Benchmark(Baseline = true)]
public void WithNonCached()
{
for (int i = 0; i < 100; i++)
{
var a = i;
2018-03-27 16:42:52 +02:00
var b = i * 10;
Expression<Func<IContent, bool>> predicate = content =>
content.Path.StartsWith("-1") && content.Published && (content.ContentTypeId == a || content.ContentTypeId == b);
2017-05-12 14:49:44 +02:00
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _mapperCollection);
var result = modelToSqlExpressionHelper.Visit(predicate);
2017-07-20 11:21:28 +02:00
}
}
2017-05-12 14:49:44 +02:00
[Benchmark]
public void WithCachedExpression()
{
for (int i = 0; i < 100; i++)
{
var a = i;
var b = i * 10;
Expression<Func<IContent, bool>> predicate = content =>
content.Path.StartsWith("-1") && content.Published && (content.ContentTypeId == a || content.ContentTypeId == b);
2017-07-20 11:21:28 +02:00
2017-05-12 14:49:44 +02:00
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _mapperCollection);
//wrap it!
_cachedExpression.Wrap(predicate);
var result = modelToSqlExpressionHelper.Visit(_cachedExpression);
}
}
}
2017-07-20 11:21:28 +02:00
}