Skip to content

Commit 0695e78

Browse files
committed
new bms @wip
1 parent c2ff871 commit 0695e78

File tree

5 files changed

+63
-35
lines changed

5 files changed

+63
-35
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ In addition, the memory consumption taken by the compilation will be much smalle
5858
**Updated to .NET 9.0**
5959

6060
```ini
61-
BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.4391/23H2/2023Update/SunValley3)
61+
BenchmarkDotNet v0.15.0, Windows 11 (10.0.26100.4061/24H2/2024Update/HudsonValley)
6262
Intel Core i9-8950HK CPU 2.90GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
63-
.NET SDK 9.0.100
64-
[Host] : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
65-
DefaultJob : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
63+
.NET SDK 9.0.203
64+
[Host] : .NET 9.0.4 (9.0.425.16305), X64 RyuJIT AVX2
65+
DefaultJob : .NET 9.0.4 (9.0.425.16305), X64 RyuJIT AVX2
6666
```
6767

6868
### Hoisted expression with the constructor and two arguments in closure
@@ -75,18 +75,18 @@ Expression<Func<X>> e = () => new X(a, b);
7575

7676
Compiling expression:
7777

78-
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Gen1 | Allocated | Alloc Ratio |
79-
| ----------- | ---------: | --------: | --------: | ----: | ------: | -----: | -----: | --------: | ----------: |
80-
| Compile | 151.570 us | 3.0196 us | 6.7538 us | 44.27 | 2.13 | 0.7324 | - | 4.49 KB | 2.92 |
81-
| CompileFast | 3.425 us | 0.0676 us | 0.0664 us | 1.00 | 0.03 | 0.2441 | 0.2365 | 1.54 KB | 1.00 |
78+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Gen1 | Allocated | Alloc Ratio |
79+
| ----------- | ---------: | --------: | --------: | ----: | ------: | ---: | -----: | -----: | --------: | ----------: |
80+
| CompileFast | 3.183 us | 0.0459 us | 0.0407 us | 1.00 | 0.02 | 1 | 0.1984 | 0.1945 | 1.23 KB | 1.00 |
81+
| Compile | 147.312 us | 1.9291 us | 1.8946 us | 46.28 | 0.81 | 2 | 0.4883 | 0.2441 | 4.48 KB | 3.65 |
8282

8383
Invoking the compiled delegate (comparing to the direct constructor call):
8484

85-
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
86-
| --------------------- | -------: | --------: | --------: | -------: | ----: | ------: | -----: | --------: | ----------: |
87-
| DirectConstructorCall | 6.920 ns | 0.2007 ns | 0.3462 ns | 7.051 ns | 0.86 | 0.06 | 0.0051 | 32 B | 1.00 |
88-
| CompiledLambda | 8.095 ns | 0.2195 ns | 0.5216 ns | 7.845 ns | 1.01 | 0.08 | 0.0051 | 32 B | 1.00 |
89-
| FastCompiledLambda | 8.066 ns | 0.2206 ns | 0.3234 ns | 8.156 ns | 1.00 | 0.06 | 0.0051 | 32 B | 1.00 |
85+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Allocated | Alloc Ratio |
86+
| --------------------- | -------: | --------: | --------: | ----: | ------: | ---: | -----: | --------: | ----------: |
87+
| DirectConstructorCall | 6.055 ns | 0.0632 ns | 0.0560 ns | 1.00 | 0.01 | 1 | 0.0051 | 32 B | 1.00 |
88+
| CompiledLambda | 7.853 ns | 0.2013 ns | 0.1681 ns | 1.30 | 0.03 | 2 | 0.0051 | 32 B | 1.00 |
89+
| FastCompiledLambda | 7.962 ns | 0.2186 ns | 0.4052 ns | 1.31 | 0.07 | 2 | 0.0051 | 32 B | 1.00 |
9090

9191

9292
### Hoisted expression with the static method and two nested lambdas and two arguments in closure
@@ -99,19 +99,18 @@ Expression<Func<X>> getXExpr = () => CreateX((aa, bb) => new X(aa, bb), new Lazy
9999

100100
Compiling expression:
101101

102-
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Gen1 | Allocated | Alloc Ratio |
103-
| ----------- | --------: | -------: | --------: | --------: | ----: | ------: | -----: | -----: | --------: | ----------: |
104-
| Compile | 421.09 us | 8.382 us | 18.221 us | 413.02 us | 36.29 | 2.09 | 1.9531 | 0.9766 | 12.04 KB | 2.61 |
105-
| CompileFast | 11.62 us | 0.230 us | 0.464 us | 11.42 us | 1.00 | 0.06 | 0.7324 | 0.7019 | 4.62 KB | 1.00 |
106-
102+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Gen1 | Allocated | Alloc Ratio |
103+
| ----------- | --------: | -------: | -------: | ----: | ------: | ---: | -----: | -----: | --------: | ----------: |
104+
| CompileFast | 11.12 us | 0.189 us | 0.158 us | 1.00 | 0.02 | 1 | 0.6104 | 0.5798 | 3.77 KB | 1.00 |
105+
| Compile | 415.09 us | 4.277 us | 3.571 us | 37.34 | 0.60 | 2 | 1.9531 | 1.4648 | 12.04 KB | 3.19 |
107106

108107
Invoking compiled delegate comparing to direct method call:
109108

110-
| Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
111-
| ------------------- | ----------: | --------: | --------: | ----------: | ----: | ------: | -----: | --------: | ----------: |
112-
| DirectMethodCall | 43.45 ns | 0.922 ns | 1.905 ns | 44.13 ns | 1.09 | 0.08 | 0.0268 | 168 B | 1.62 |
113-
| Invoke_Compiled | 1,181.25 ns | 23.664 ns | 56.240 ns | 1,161.87 ns | 29.66 | 2.24 | 0.0420 | 264 B | 2.54 |
114-
| Invoke_CompiledFast | 39.96 ns | 0.856 ns | 2.442 ns | 38.96 ns | 1.00 | 0.08 | 0.0166 | 104 B | 1.00 |
109+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Allocated | Alloc Ratio |
110+
| ------------------- | ----------: | --------: | --------: | ----: | ------: | ---: | -----: | --------: | ----------: |
111+
| DirectMethodCall | 40.29 ns | 0.549 ns | 0.487 ns | 1.00 | 0.02 | 1 | 0.0268 | 168 B | 1.00 |
112+
| Invoke_CompiledFast | 40.59 ns | 0.157 ns | 0.123 ns | 1.01 | 0.01 | 1 | 0.0166 | 104 B | 0.62 |
113+
| Invoke_Compiled | 1,142.12 ns | 11.877 ns | 14.586 ns | 28.35 | 0.48 | 2 | 0.0420 | 264 B | 1.57 |
115114

116115

117116
### Manually composed expression with parameters and closure

test/FastExpressionCompiler.Benchmarks/FastExpressionCompiler.Benchmarks.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="BenchmarkDotNet" Version="0.14.0"/>
21-
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
20+
<PackageReference Include="BenchmarkDotNet" Version="0.15.0"/>
21+
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.15.0" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

test/FastExpressionCompiler.Benchmarks/HoistedLambdaBenchmark.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static System.Linq.Expressions.Expression<Func<X>> GetHoistedExpr()
1717

1818
private static readonly System.Linq.Expressions.Expression<Func<X>> _hoistedExpr = GetHoistedExpr();
1919

20-
[MemoryDiagnoser]
20+
[MemoryDiagnoser, RankColumn, Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)]
2121
public class Compilation
2222
{
2323
/*
@@ -144,6 +144,20 @@ .NET SDK 9.0.203
144144
|------------ |-----------:|----------:|----------:|------:|--------:|-------:|-------:|----------:|------------:|
145145
| Compile | 149.614 us | 2.8135 us | 2.7633 us | 47.01 | 1.58 | 0.7324 | - | 4.49 KB | 3.66 |
146146
| CompileFast | 3.185 us | 0.0629 us | 0.0941 us | 1.00 | 0.04 | 0.1984 | 0.1907 | 1.23 KB | 1.00 |
147+
148+
## v5.3.0 + BDN v0.15.0
149+
150+
BenchmarkDotNet v0.15.0, Windows 11 (10.0.26100.4061/24H2/2024Update/HudsonValley)
151+
Intel Core i9-8950HK CPU 2.90GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
152+
.NET SDK 9.0.203
153+
[Host] : .NET 9.0.4 (9.0.425.16305), X64 RyuJIT AVX2
154+
DefaultJob : .NET 9.0.4 (9.0.425.16305), X64 RyuJIT AVX2
155+
156+
157+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Gen1 | Allocated | Alloc Ratio |
158+
|------------ |-----------:|----------:|----------:|------:|--------:|-----:|-------:|-------:|----------:|------------:|
159+
| CompileFast | 3.183 us | 0.0459 us | 0.0407 us | 1.00 | 0.02 | 1 | 0.1984 | 0.1945 | 1.23 KB | 1.00 |
160+
| Compile | 147.312 us | 1.9291 us | 1.8946 us | 46.28 | 0.81 | 2 | 0.4883 | 0.2441 | 4.48 KB | 3.65 |
147161
*/
148162

149163
[Benchmark]
@@ -156,7 +170,7 @@ .NET SDK 9.0.203
156170
public object ConvertToLight_CompileFast() => _hoistedExpr.ToLightExpression().CompileFast();
157171
}
158172

159-
[MemoryDiagnoser]
173+
[MemoryDiagnoser, RankColumn, Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)]
160174
public class Invocation
161175
{
162176
/*
@@ -235,6 +249,14 @@ .NET SDK 8.0.100-rc.2.23502.2
235249
| DirectConstructorCall | 5.734 ns | 0.1501 ns | 0.2745 ns | 5.679 ns | 0.86 | 0.05 | 0.0051 | 32 B | 1.00 |
236250
| CompiledLambda | 6.857 ns | 0.1915 ns | 0.5434 ns | 6.704 ns | 1.01 | 0.09 | 0.0051 | 32 B | 1.00 |
237251
| FastCompiledLambda | 6.746 ns | 0.1627 ns | 0.1442 ns | 6.751 ns | 1.00 | 0.00 | 0.0051 | 32 B | 1.00 |
252+
253+
## v5.3.0 + BDN v0.15.0
254+
255+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Allocated | Alloc Ratio |
256+
|---------------------- |---------:|----------:|----------:|------:|--------:|-----:|-------:|----------:|------------:|
257+
| DirectConstructorCall | 6.055 ns | 0.0632 ns | 0.0560 ns | 1.00 | 0.01 | 1 | 0.0051 | 32 B | 1.00 |
258+
| CompiledLambda | 7.853 ns | 0.2013 ns | 0.1681 ns | 1.30 | 0.03 | 2 | 0.0051 | 32 B | 1.00 |
259+
| FastCompiledLambda | 7.962 ns | 0.2186 ns | 0.4052 ns | 1.31 | 0.07 | 2 | 0.0051 | 32 B | 1.00 |
238260
*/
239261

240262
private static readonly Func<X> _lambdaCompiled = _hoistedExpr.Compile();
@@ -243,15 +265,15 @@ .NET SDK 8.0.100-rc.2.23502.2
243265
private readonly A _aa = new A();
244266
private readonly B _bb = new B();
245267

246-
[Benchmark]
268+
[Benchmark(Baseline = true)]
247269
public object DirectConstructorCall() =>
248270
new X(_aa, _bb);
249271

250272
[Benchmark]
251273
public object CompiledLambda() =>
252274
_lambdaCompiled();
253275

254-
[Benchmark(Baseline = true)]
276+
[Benchmark]
255277
public object FastCompiledLambda() =>
256278
_lambdaCompiledFast();
257279
}

test/FastExpressionCompiler.Benchmarks/HoistedLambdaWithNestedLambdaBenchmark.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static Expression<Func<X>> GetHoistedExpr()
1818

1919
private static readonly Expression<Func<X>> _hoistedExpr = GetHoistedExpr();
2020

21-
[MemoryDiagnoser]
21+
[MemoryDiagnoser, RankColumn, Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)]
2222
public class Compilation
2323
{
2424
/*
@@ -144,6 +144,13 @@ .NET SDK 9.0.100
144144
| Compile | 437.16 us | 8.631 us | 20.004 us | 438.94 us | 39.26 | 3.33 | 1.9531 | 0.9766 | 12.04 KB | 3.19 |
145145
| CompileFast | 11.20 us | 0.329 us | 0.896 us | 10.93 us | 1.01 | 0.11 | 0.6104 | 0.5951 | 3.77 KB | 1.00 |
146146
147+
## v5.3.0 + BDN v0.15.0
148+
149+
| Method | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Gen1 | Allocated | Alloc Ratio |
150+
|------------ |----------:|---------:|---------:|------:|--------:|-----:|-------:|-------:|----------:|------------:|
151+
| CompileFast | 11.12 us | 0.189 us | 0.158 us | 1.00 | 0.02 | 1 | 0.6104 | 0.5798 | 3.77 KB | 1.00 |
152+
| Compile | 415.09 us | 4.277 us | 3.571 us | 37.34 | 0.60 | 2 | 1.9531 | 1.4648 | 12.04 KB | 3.19 |
153+
147154
*/
148155
[Benchmark]
149156
public Func<X> Compile() => _hoistedExpr.Compile();
@@ -152,7 +159,7 @@ .NET SDK 9.0.100
152159
public Func<X> CompileFast() => _hoistedExpr.CompileFast();
153160
}
154161

155-
[MemoryDiagnoser]
162+
[MemoryDiagnoser, RankColumn, Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)]
156163
public class Invocation
157164
{
158165
/*
@@ -253,15 +260,15 @@ .NET SDK 9.0.100
253260
private readonly A _aa = new A();
254261
private readonly B _bb = new B();
255262

256-
[Benchmark]
263+
[Benchmark(Baseline = true)]
257264
public X DirectMethodCall() =>
258265
CreateX((a, b) => new X(a, b), new Lazy<A>(() => _aa), _bb);
259266

260267
[Benchmark]
261268
public X Invoke_Compiled() =>
262269
_lambdaCompiled();
263270

264-
[Benchmark(Baseline = true)]
271+
[Benchmark]
265272
public X Invoke_CompiledFast() =>
266273
_lambdaCompiledFast();
267274
}

test/FastExpressionCompiler.Benchmarks/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void Main()
1313
// BenchmarkRunner.Run<HoistedLambdaBenchmark.Invocation>();
1414

1515
// BenchmarkRunner.Run<HoistedLambdaWithNestedLambdaBenchmark.Compilation>();
16-
// BenchmarkRunner.Run<HoistedLambdaWithNestedLambdaBenchmark.Invocation>();
16+
BenchmarkRunner.Run<HoistedLambdaWithNestedLambdaBenchmark.Invocation>();
1717

1818
// BenchmarkRunner.Run<ManuallyComposedLambdaBenchmark.Compilation>();
1919
// BenchmarkRunner.Run<ManuallyComposedLambdaBenchmark.Invocation>();
@@ -37,7 +37,7 @@ public static void Main()
3737

3838
// BenchmarkRunner.Run<EmitHacks.MethodStaticNoArgsEmit>();
3939

40-
BenchmarkRunner.Run<ExprLinqAnyOfNotNullDecimal.Compile>();
40+
// BenchmarkRunner.Run<ExprLinqAnyOfNotNullDecimal.Compile>();
4141
// BenchmarkRunner.Run<ExprLinqAnyOfNotNullDecimal.Invoke>();
4242

4343
// BenchmarkRunner.Run<RepoDb_ListInit.Compile>();

0 commit comments

Comments
 (0)