-
Notifications
You must be signed in to change notification settings - Fork 15
/
TemplateBenchmarks.cs
63 lines (48 loc) · 1.6 KB
/
TemplateBenchmarks.cs
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
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
namespace Mjml.Net.Benchmarking;
[Config(typeof(Config))]
[MemoryDiagnoser]
public class TemplateBenchmarks
{
private static readonly MjmlOptions WithBeautify = new MjmlOptions { Beautify = true };
private readonly MjmlRenderer MjmlRenderer;
[ParamsSource(nameof(MjmlTemplates))]
public string MjmlTemplateFilePath { get; set; }
public static IEnumerable<string> MjmlTemplates => Directory.GetFiles("./Templates/", "*.mjml");
public string MjmlTemplate { get; set; }
public class Config : ManualConfig
{
public Config()
{
var baseJob = Job.ShortRun;
AddJob(baseJob
.WithId("Dev").WithBaseline(true));
AddJob(baseJob.WithCustomBuildConfiguration("V1_24")
.WithId("1.24.0"));
AddJob(baseJob.WithCustomBuildConfiguration("V2_0")
.WithId("2.0.0"));
AddJob(baseJob.WithCustomBuildConfiguration("V2_1")
.WithId("2.1.0"));
AddJob(baseJob.WithCustomBuildConfiguration("V3_8")
.WithId("3.8.0"));
AddExporter(MarkdownExporter.GitHub);
}
}
public TemplateBenchmarks()
{
MjmlRenderer = new();
}
[GlobalSetup]
public void GlobalSetup()
{
MjmlTemplate = File.ReadAllText(MjmlTemplateFilePath);
}
[Benchmark()]
public string Render_Template_Beautify()
{
return MjmlRenderer.Render(MjmlTemplate, WithBeautify).Html;
}
}