2016-10-27 17:36:08 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Data.SqlServerCe;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using BenchmarkDotNet.Attributes;
|
|
|
|
|
|
using BenchmarkDotNet.Columns;
|
|
|
|
|
|
using BenchmarkDotNet.Configs;
|
|
|
|
|
|
using BenchmarkDotNet.Diagnosers;
|
|
|
|
|
|
using BenchmarkDotNet.Diagnostics.Windows;
|
|
|
|
|
|
using BenchmarkDotNet.Jobs;
|
|
|
|
|
|
using BenchmarkDotNet.Loggers;
|
|
|
|
|
|
using BenchmarkDotNet.Reports;
|
|
|
|
|
|
using BenchmarkDotNet.Running;
|
|
|
|
|
|
using BenchmarkDotNet.Validators;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Models.Rdbms;
|
|
|
|
|
|
using Umbraco.Core.Persistence;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Mappers;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Migrations.Initial;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Querying;
|
|
|
|
|
|
using Umbraco.Core.Persistence.SqlSyntax;
|
|
|
|
|
|
using Umbraco.Tests.TestHelpers;
|
|
|
|
|
|
using ILogger = Umbraco.Core.Logging.ILogger;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Benchmarks
|
|
|
|
|
|
{
|
|
|
|
|
|
[Config(typeof(Config))]
|
|
|
|
|
|
public class ModelToSqlExpressionHelperBenchmarks
|
|
|
|
|
|
{
|
|
|
|
|
|
private class Config : ManualConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public Config()
|
|
|
|
|
|
{
|
|
|
|
|
|
Add(new MemoryDiagnoser());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ModelToSqlExpressionHelperBenchmarks()
|
|
|
|
|
|
{
|
2016-11-23 10:33:12 +01:00
|
|
|
|
_contentMapper = new ContentMapper();
|
|
|
|
|
|
// _contentMapper.BuildMap(); // fixme - protected?
|
2016-10-27 17:36:08 +02:00
|
|
|
|
_cachedExpression = new CachedExpression();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ISqlSyntaxProvider _syntaxProvider = new SqlCeSyntaxProvider();
|
|
|
|
|
|
private readonly BaseMapper _contentMapper;
|
|
|
|
|
|
private readonly CachedExpression _cachedExpression;
|
2016-10-27 17:50:52 +02:00
|
|
|
|
|
2016-10-27 17:36:08 +02:00
|
|
|
|
[Benchmark(Baseline = true)]
|
|
|
|
|
|
public void WithNonCached()
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2016-10-28 16:30:20 +02:00
|
|
|
|
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _contentMapper);
|
2016-10-27 17:36:08 +02:00
|
|
|
|
var result = modelToSqlExpressionHelper.Visit(predicate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-27 17:38:04 +02:00
|
|
|
|
|
2016-10-27 17:36:08 +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);
|
|
|
|
|
|
|
2016-10-28 16:30:20 +02:00
|
|
|
|
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _contentMapper);
|
2016-10-27 17:36:08 +02:00
|
|
|
|
|
|
|
|
|
|
//wrap it!
|
|
|
|
|
|
_cachedExpression.Wrap(predicate);
|
|
|
|
|
|
|
|
|
|
|
|
var result = modelToSqlExpressionHelper.Visit(_cachedExpression);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|