-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageServiceBenchmarks.cs
More file actions
48 lines (43 loc) · 1.66 KB
/
Copy pathLanguageServiceBenchmarks.cs
File metadata and controls
48 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Reflection;
using BenchmarkDotNet.Attributes;
using Heddle.Data;
using Heddle.Runtime;
namespace Heddle.Performance;
/// <summary>
/// The phase 6 null-cost guard: compiles a home-page-sized template with <see cref="TemplateOptions.ProvideLanguageFeatures"/>
/// off (must equal the pre-phase baseline — the scope map is never created, one null check per body compile) and
/// on (the documented budget: within 10% mean / 5% allocated of flag-off). <c>[MemoryDiagnoser]</c> so allocated
/// bytes are compared, not just time.
/// </summary>
[MemoryDiagnoser]
public class LanguageServiceBenchmarks
{
private const string HomePage = """
@model(){{object}}
<html><head><title>Heddle</title></head><body>
<h1>@(Title)</h1>
@if(HasItems){{<ul>@list(Items){{<li>@(Name): @(Value)</li>}}</ul>}}
@for(3){{<span>row @out()</span>}}
<footer>@(Year)</footer>
</body></html>
""";
[GlobalSetup]
public void Setup()
{
HeddleTemplate.Configure(typeof(LanguageServiceBenchmarks).GetTypeInfo().Assembly);
}
[Benchmark(Baseline = true)]
public bool CompileFlagOff()
{
var options = new TemplateOptions { ProvideLanguageFeatures = false };
var template = new HeddleTemplate(HomePage, new CompileContext(options, typeof(object)));
return template.CompileResult != null;
}
[Benchmark]
public bool CompileFlagOn()
{
var options = new TemplateOptions { ProvideLanguageFeatures = true };
var template = new HeddleTemplate(HomePage, new CompileContext(options, typeof(object)));
return template.CompileResult != null;
}
}