-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Build overloads take no parameter Add Build method documentations * remove compiled build methods * Add BuildCompiled method * add BuildFilteringExpression test * add QueryBuilderBuildBenchmark * remove test todo * BuildOrderingExpression removed. this method is not useful because we don't know ordering is ascending or descending, also simple use the output expressions on LINQ OrderBy methods doesn't work because we need to use ThenBy on second orderings. * remove orderBy from QueryBuilderBuildBenchmark * update to v2.4.2 * fix BuildWithPagingCompiled * Add BuildWithPagingCompiled * fix description
- Loading branch information
1 parent
a020b60
commit 406b518
Showing
10 changed files
with
344 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
using BenchmarkDotNet.Order; | ||
using Gridify; | ||
using Gridify.Tests; | ||
|
||
namespace Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
[RPlotExporter] | ||
[Orderer(SummaryOrderPolicy.FastestToSlowest)] | ||
public class QueryBuilderBuildBenchmark | ||
{ | ||
private readonly IEnumerable<TestClass> _data; | ||
private static readonly Consumer Consumer = new(); | ||
private readonly Func<IEnumerable<TestClass>, IEnumerable<TestClass>> BuildCompiledFuc; | ||
private readonly Func<IQueryable<TestClass>, IQueryable<TestClass>> BuildFunc; | ||
private readonly Func<TestClass, bool> BuildFilteringExpressionFunc; | ||
private readonly Func<IEnumerable<TestClass>, Paging<TestClass>> BuildWithPagingCompiledFunc; | ||
private readonly Func<IQueryable<TestClass>, Paging<TestClass>> BuildWithPagingFunc; | ||
|
||
|
||
public QueryBuilderBuildBenchmark() | ||
{ | ||
_data = LibraryComparisionFilteringBenchmark.GetSampleData().ToArray(); | ||
|
||
var builder = new QueryBuilder<TestClass>() | ||
.AddCondition("id>2") | ||
.AddCondition("name=*a"); | ||
|
||
BuildCompiledFuc = builder.BuildCompiled(); | ||
BuildFunc = builder.Build(); | ||
BuildFilteringExpressionFunc = builder.BuildFilteringExpression().Compile(); | ||
BuildWithPagingCompiledFunc = builder.BuildWithPagingCompiled(); | ||
BuildWithPagingFunc = builder.BuildWithPaging(); | ||
|
||
TestOutputs(); | ||
} | ||
|
||
[Benchmark(Baseline = true)] // this method is only for filtering operations | ||
public void UseGetFilteringExpression() | ||
{ | ||
_data.Where(BuildFilteringExpressionFunc).Consume(Consumer); | ||
} | ||
|
||
[Benchmark] | ||
public void Build() | ||
{ | ||
BuildFunc(_data.AsQueryable()).Consume(Consumer); | ||
} | ||
|
||
[Benchmark] | ||
public void BuildCompiled() | ||
{ | ||
BuildCompiledFuc(_data).Consume(Consumer); | ||
} | ||
|
||
[Benchmark] | ||
public void BuildWithPaging() | ||
{ | ||
BuildWithPagingFunc(_data.AsQueryable()).Data.Consume(Consumer); | ||
} | ||
|
||
[Benchmark] | ||
public void BuildWithPagingCompiled() | ||
{ | ||
BuildWithPagingCompiledFunc(_data.AsQueryable()).Data.Consume(Consumer); | ||
} | ||
|
||
private void TestOutputs() | ||
{ | ||
if (AllSame(BuildCompiledFuc(_data).Count(), BuildFunc(_data.AsQueryable()).Count(), _data.Where(BuildFilteringExpressionFunc).Count()) && | ||
AllSame(BuildCompiledFuc(_data).First().Id, BuildFunc(_data.AsQueryable()).First().Id, | ||
_data.Where(BuildFilteringExpressionFunc).First().Id) && | ||
AllSame(BuildCompiledFuc(_data).Last().Id, BuildFunc(_data.AsQueryable()).Last().Id, | ||
_data.Where(BuildFilteringExpressionFunc).Last().Id) && | ||
BuildCompiledFuc(_data).Count() < 2) | ||
{ | ||
throw new Exception("MISS MATCH OUTPUT"); | ||
} | ||
} | ||
|
||
private static bool AllSame<T>(params T[] items) | ||
{ | ||
var first = true; | ||
T comparand = default; | ||
foreach (var i in items) | ||
{ | ||
if (first) comparand = i; | ||
else if (!i.Equals(comparand)) return false; | ||
first = false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.