Skip to content

Commit 67020d0

Browse files
authored
Merge pull request #4 from willysoft/feature/add-benchmarking
chore: Add benchmarking project and performance comparison
2 parents 7c76e0c + a1d929f commit 67020d0

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

AutoQuery.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoQueryApiDemo", "sample\
2626
EndProject
2727
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoQuery.AspNetCore.Tests", "test\AutoQuery.AspNetCore.Tests\AutoQuery.AspNetCore.Tests.csproj", "{A9125D44-3F97-4251-85F7-B28D07FA7B2D}"
2828
EndProject
29+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sandbox", "sandbox", "{75B3287A-5C54-494A-B646-72CFBF9E2FB2}"
30+
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoQuery.Benchmark", "sandbox\AutoQuery.Benchmark\AutoQuery.Benchmark.csproj", "{6F332D4E-4C59-40C7-836F-C7344FD9ACD5}"
32+
EndProject
2933
Global
3034
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3135
Debug|Any CPU = Debug|Any CPU
@@ -56,6 +60,10 @@ Global
5660
{A9125D44-3F97-4251-85F7-B28D07FA7B2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
5761
{A9125D44-3F97-4251-85F7-B28D07FA7B2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
5862
{A9125D44-3F97-4251-85F7-B28D07FA7B2D}.Release|Any CPU.Build.0 = Release|Any CPU
63+
{6F332D4E-4C59-40C7-836F-C7344FD9ACD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
64+
{6F332D4E-4C59-40C7-836F-C7344FD9ACD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
65+
{6F332D4E-4C59-40C7-836F-C7344FD9ACD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
66+
{6F332D4E-4C59-40C7-836F-C7344FD9ACD5}.Release|Any CPU.Build.0 = Release|Any CPU
5967
EndGlobalSection
6068
GlobalSection(SolutionProperties) = preSolution
6169
HideSolutionNode = FALSE
@@ -67,6 +75,7 @@ Global
6775
{AEAB6CC3-1A1D-450D-A368-6A3BAF82A4DE} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
6876
{BF0093CA-57E3-4D5F-91B9-46898DFDD0C1} = {E97A2640-E7C7-4C4B-B3E2-311C1B9FDAA4}
6977
{A9125D44-3F97-4251-85F7-B28D07FA7B2D} = {5730CC15-795B-43C9-802C-18B3E19B7E22}
78+
{6F332D4E-4C59-40C7-836F-C7344FD9ACD5} = {75B3287A-5C54-494A-B646-72CFBF9E2FB2}
7079
EndGlobalSection
7180
GlobalSection(ExtensibilityGlobals) = postSolution
7281
SolutionGuid = {8FA10855-B537-4BAA-BB5B-6C0FB0BA6F42}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
- **Pagination and Sorting**: Built-in support for pagination and sorting.
1313
- **ASP.NET Core Integration**: Middleware support for easy integration into ASP.NET Core projects.
1414

15+
## Benchmark
16+
17+
The benchmark results provide an overview of `AutoQuery`'s performance in handling dynamic queries and filtering. These results can help evaluate its suitability for various application scenarios.
18+
19+
![](imgs/benchmarks.jpg)
20+
1521
## Installation
1622

1723
### AutoQuery

imgs/benchmarks.jpg

27.7 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
13+
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.2" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\src\AutoQuery\AutoQuery.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Diagnosers;
3+
using BenchmarkDotNet.Environments;
4+
using BenchmarkDotNet.Jobs;
5+
6+
namespace AutoQuery.Benchmark;
7+
8+
internal class BenchmarkConfig : ManualConfig
9+
{
10+
public BenchmarkConfig()
11+
{
12+
AddDiagnoser(MemoryDiagnoser.Default);
13+
AddJob(Job.ShortRun
14+
.WithWarmupCount(1)
15+
.WithIterationCount(1)
16+
.WithRuntime(CoreRuntime.Core80));
17+
}
18+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using AutoQuery.Abstractions;
2+
using AutoQuery.Extensions;
3+
using BenchmarkDotNet.Attributes;
4+
using System.Linq.Dynamic.Core;
5+
using System.Reflection;
6+
7+
namespace AutoQuery.Benchmark.Benchmarks;
8+
9+
[Config(typeof(BenchmarkConfig))]
10+
public class QueryPerformance
11+
{
12+
private List<TestData> _autoQueryTestData = null!;
13+
private List<TestData> _dynamicLinqTestData = null!;
14+
private QueryProcessor _queryProcessor = null!;
15+
16+
[GlobalSetup]
17+
public void Setup()
18+
{
19+
_queryProcessor = new QueryProcessor();
20+
_queryProcessor.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
21+
_autoQueryTestData = Enumerable.Range(1, 10000)
22+
.Select(i => new TestData { Id = i, Name = $"Name{i}", Age = i % 100 })
23+
.ToList();
24+
_dynamicLinqTestData = Enumerable.Range(1, 10000)
25+
.Select(i => new TestData { Id = i, Name = $"Name{i}", Age = i % 100 })
26+
.ToList();
27+
}
28+
29+
[Benchmark]
30+
public void FilterSortSelectPageWithAutoQuery()
31+
{
32+
var queryOptions = new TestQueryOptions
33+
{
34+
Name = "Name5000",
35+
Sort = "Age",
36+
Fields = "Id,Name",
37+
Page = 1,
38+
PageSize = 10
39+
};
40+
41+
_autoQueryTestData.AsQueryable().ApplyQueryPaged(_queryProcessor, queryOptions);
42+
}
43+
44+
[Benchmark]
45+
public void FilterSortSelectPageWithDynamicLinq()
46+
{
47+
_dynamicLinqTestData.AsQueryable()
48+
.Where("Name == @0", "Name5000")
49+
.OrderBy("Age")
50+
.Select("new (Id, Name)")
51+
.Skip(0)
52+
.Take(10)
53+
.ToDynamicList();
54+
}
55+
56+
public class UserQueryConfiguration : IFilterQueryConfiguration<TestQueryOptions, TestData>
57+
{
58+
public void Configure(FilterQueryBuilder<TestQueryOptions, TestData> builder)
59+
{
60+
builder.Property(q => q.Name, d => d.Name)
61+
.HasEqual();
62+
}
63+
}
64+
65+
public class TestData
66+
{
67+
public int Id { get; set; }
68+
public string Name { get; set; } = null!;
69+
public int Age { get; set; }
70+
}
71+
72+
public class TestQueryOptions : IQueryPagedOptions
73+
{
74+
public string? Name { get; set; }
75+
public string? Fields { get; set; }
76+
public string? Sort { get; set; }
77+
public int? Page { get; set; }
78+
public int? PageSize { get; set; }
79+
}
80+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using BenchmarkDotNet.Running;
2+
using System.Reflection;
3+
4+
BenchmarkSwitcher.FromAssembly(Assembly.GetEntryAssembly()!).Run(args);

0 commit comments

Comments
 (0)