Skip to content

Commit 6b72ab6

Browse files
committed
Add tests highlighting cost of non-reflective runtime splice evaluation
1 parent 0c39492 commit 6b72ab6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Arborist/test/InterpolateBenchmarks.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,36 @@ public void Runtime() {
3636
var data = new { SpliceExpression, SpliceBodyExpression, SplicedValue };
3737

3838
Benchmark(nameof(Runtime), data, static data => {
39-
ExpressionOn<Owner>.InterpolateRuntimeFallback(data, (x, o) =>
39+
ExpressionOn<Owner>.InterpolateRuntimeFallback(data, static (x, o) =>
4040
o.Name == x.SpliceConstant(x.Data.SplicedValue)
4141
&& o.Cats.Any(c => x.SpliceBody(c.Name, x.Data.SpliceBodyExpression))
4242
&& o.Dogs.Any(x.Splice(x.Data.SpliceExpression))
4343
);
4444
});
4545
}
4646

47+
[Fact]
48+
public void CompileTime_requiring_runtime_expression_compilation() {
49+
var data = new { Value = 42 };
50+
51+
Benchmark(nameof(CompileTime_requiring_runtime_expression_compilation), data, static data => {
52+
ExpressionOn<Owner>.Interpolate(data, static (x, o) =>
53+
o.Id + x.SpliceConstant(x.Data.Value + 1)
54+
);
55+
});
56+
}
57+
58+
[Fact]
59+
public void Runtime_requiring_runtime_expression_compilation() {
60+
var data = new { Value = 42 };
61+
62+
Benchmark(nameof(Runtime_requiring_runtime_expression_compilation), data, static data => {
63+
ExpressionOn<Owner>.InterpolateRuntimeFallback(data, static (x, o) =>
64+
o.Id + x.SpliceConstant(x.Data.Value + 1)
65+
);
66+
});
67+
}
68+
4769
private void Benchmark<TData>(string title, TData data, Action<TData> action) {
4870
for(var i = 0; i < WARMUP_ITERATIONS; i++)
4971
action(data);

0 commit comments

Comments
 (0)