-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (80 loc) · 2.23 KB
/
Program.cs
File metadata and controls
101 lines (80 loc) · 2.23 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
// See https://aka.ms/new-console-template for more information
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using MN.L10n;
using MN.L10n.FileProviders;
using System.Collections.Concurrent;
using System.Reflection;
using System.Text;
using static System.Runtime.InteropServices.JavaScript.JSType;
BenchmarkRunner.Run<Benchmarks>();
public class BenchmarkL10nLanguageProvider : IL10nLanguageProvider
{
public string GetLanguage()
{
return "1";
}
}
public class BenchmarkL10nDataProvider : IL10nDataProvider
{
private L10n _l10n = new();
public L10n LoadL10n()
{
return _l10n;
}
public Task<bool> LoadTranslationFromSources(L10n l10n, bool removeAllPhrases, CancellationToken token)
{
return Task.FromResult(true);
}
public bool SaveL10n(L10n l10n)
{
_l10n = l10n;
return true;
}
public bool SaveTranslation(L10n l10n)
{
return true;
}
}
public class Foo
{
public string data { get; set; } = "";
}
[MemoryDiagnoser(true)]
[InvocationCount(100_000)]
public class Benchmarks
{
[Params("$data$", "Hej $data$ $count$ $many$", "$den här texten inleds med $data$$data2$", "Här har vi en längre förklarande text utan dollartecken. Den här skulle t.ex. kunna finnas i ")]
public string formatString { get; set; } = "";
public static Foo args = new Foo { data = "Anders" };
[GlobalSetup]
public void GlobalSetup()
{
var dataProvider = new BenchmarkL10nDataProvider();
var stack = new Stack<string>();
stack.Push("1");
var items = new Dictionary<object, object>() { { "___l10nlang", stack } };
var l10n = L10n.CreateInstance(new BenchmarkL10nLanguageProvider(), new FileDataProvider(AppDomain.CurrentDomain.BaseDirectory), () => items);
dataProvider.SaveL10n(l10n);
}
[Benchmark]
public void GetPhase()
{
L10n._s(formatString, args);
}
[Benchmark]
public void GetPhaseWithoutArgs()
{
L10n._s(formatString);
}
[Benchmark]
public void FormatNamed()
{
L10n.FormatNamed(formatString, args);
}
[Benchmark]
public void GetLanguage()
{
L10n.GetLanguage();
}
}