forked from sebastienros/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FluidBenchmarks.cs
46 lines (40 loc) · 1.43 KB
/
FluidBenchmarks.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
using BenchmarkDotNet.Attributes;
namespace Fluid.Benchmarks
{
[MemoryDiagnoser]
public class FluidBenchmarks : BaseBenchmarks
{
private readonly TemplateOptions _options = new TemplateOptions();
private readonly FluidParser _parser = new FluidParser();
private readonly IFluidTemplate _fluidTemplate;
public FluidBenchmarks()
{
_options.MemberAccessStrategy.Register<Product>();
_options.MemberAccessStrategy.MemberNameStrategy = MemberNameStrategies.CamelCase;
_parser.TryParse(ProductTemplate, out _fluidTemplate, out var _);
}
[Benchmark]
public override object Parse()
{
return _parser.Parse(ProductTemplate);
}
[Benchmark]
public override object ParseBig()
{
return _parser.Parse(BlogPostTemplate);
}
[Benchmark]
public override string Render()
{
var context = new TemplateContext(_options).SetValue("products", Products);
return _fluidTemplate.Render(context);
}
[Benchmark]
public override string ParseAndRender()
{
_parser.TryParse(ProductTemplate, out var template);
var context = new TemplateContext(_options).SetValue("products", Products);
return template.Render(context);
}
}
}