-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextRenderBenchmarks.cs
More file actions
129 lines (111 loc) · 4.26 KB
/
Copy pathTextRenderBenchmarks.cs
File metadata and controls
129 lines (111 loc) · 4.26 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Html;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
using Heddle.Native;
using Heddle.Performance.Runners;
using Heddle.Performance.TestSuite;
namespace Heddle.Performance;
[MemoryDiagnoser]
public class TextRenderBenchmarks
{
private IHost _host;
private HeddleTest _heddleTest;
private RazorTest _razorTest;
private FluidTest _fluidTest;
#if !NET6_0
private ScribanTest _scribanTest;
#endif
private DotLiquidTest _dotLiquidTest;
private HandlebarsTest _handlebarsTest;
[GlobalSetup]
public async Task Setup() {
_host = Host.CreateDefaultBuilder()
.ConfigureServices(ConfigureDefaultServices)
.ConfigureLogging(logging => logging.AddConsole(co => co.LogToStandardErrorThreshold = LogLevel.Warning))
.Build();
await _host.StartAsync();
_heddleTest = new HeddleTest();
_razorTest = new RazorTest(_host.Services);
_fluidTest = new FluidTest();
#if !NET6_0
_scribanTest = new ScribanTest();
#endif
_dotLiquidTest = new DotLiquidTest();
_handlebarsTest = new HandlebarsTest();
// D1-R3: every competitor twin must render output identical to Heddle (after the single
// documented normalization) before we time anything, so a drifted twin fails loudly rather
// than benchmarking different work.
ParityCheck.Assert();
}
[GlobalCleanup]
public async Task Teardown() {
await _host.StopAsync();
}
// D1-R5: Heddle is the ratio baseline for the render suite.
[Benchmark(Baseline = true)]
public async Task RenderHeddle() {
await _heddleTest.Run();
}
[Benchmark]
public async Task RenderRazor() {
await _razorTest.Run();
}
[Benchmark]
public async Task RenderFluid() {
await _fluidTest.Run();
}
#if !NET6_0
[Benchmark]
public async Task RenderScriban() {
await _scribanTest.Run();
}
#endif
[Benchmark]
public async Task RenderDotLiquid() {
await _dotLiquidTest.Run();
}
[Benchmark]
public async Task RenderHandlebars() {
await _handlebarsTest.Run();
}
private static void ConfigureDefaultServices(IServiceCollection services) {
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore");
services.AddSingleton<DiagnosticSource>(diagnosticSource);
services.AddLogging();
services.AddControllersWithViews();
services.AddRazorPages().AddRazorRuntimeCompilation().AddApplicationPart(typeof(Program).Assembly);
services.AddSingleton<RazorViewToStringRenderer>();
services.AddSingleton<DiagnosticSource>(diagnosticSource);
services.AddSingleton<DiagnosticListener>(diagnosticSource);
var appDirectory = Directory.GetCurrentDirectory();
var fileProvider = new PhysicalFileProvider(appDirectory);
services.AddSingleton<IWebHostEnvironment>(new HostingEnvironment(fileProvider, appDirectory));
AssemblyHelper.Configure(typeof(Program).GetTypeInfo().Assembly);
AssemblyHelper.Configure(typeof(IHtmlContent).GetTypeInfo().Assembly);
}
internal class HostingEnvironment : IWebHostEnvironment
{
public HostingEnvironment(IFileProvider contentRootFileProvider, string webRootPath) {
ContentRootFileProvider = contentRootFileProvider;
WebRootPath = webRootPath;
ContentRootPath = webRootPath;
WebRootFileProvider = contentRootFileProvider;
}
public string EnvironmentName { get; set; } = "Production";
public string ApplicationName { get; set; } = "Heddle.Performance";
public string WebRootPath { get; set; }
public IFileProvider WebRootFileProvider { get; set; }
public string ContentRootPath { get; set; }
public IFileProvider ContentRootFileProvider { get; set; }
}
}