Skip to content

Commit d12f0f1

Browse files
author
anmo
committed
Merge branch 'master' into perf-work
2 parents 9e13c40 + 84dcb16 commit d12f0f1

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\MN.L10n\MN.L10n.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

MN.L10n.Benchmark/Program.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// See https://aka.ms/new-console-template for more information
2+
using BenchmarkDotNet.Attributes;
3+
using BenchmarkDotNet.Running;
4+
using MN.L10n;
5+
using System.Collections.Concurrent;
6+
using System.Reflection;
7+
using System.Text;
8+
using static System.Runtime.InteropServices.JavaScript.JSType;
9+
10+
11+
12+
13+
BenchmarkRunner.Run<SpanTest>();
14+
15+
16+
17+
18+
public class BenchmarkL10nLanguageProvider : IL10nLanguageProvider
19+
{
20+
public string GetLanguage()
21+
{
22+
return "0";
23+
}
24+
}
25+
26+
public class BenchmarkL10nDataProvider : IL10nDataProvider
27+
{
28+
private L10n _l10n = new();
29+
public L10n LoadL10n()
30+
{
31+
return _l10n;
32+
}
33+
34+
public Task<bool> LoadTranslationFromSources(L10n l10n, bool removeAllPhrases, CancellationToken token)
35+
{
36+
return Task.FromResult(true);
37+
}
38+
39+
public bool SaveL10n(L10n l10n)
40+
{
41+
_l10n = l10n;
42+
return true;
43+
}
44+
45+
public bool SaveTranslation(L10n l10n)
46+
{
47+
return true;
48+
}
49+
}
50+
51+
52+
public class Foo
53+
{
54+
public string data { get; set; } = "";
55+
}
56+
57+
[MemoryDiagnoser(true)]
58+
[InvocationCount(100000)]
59+
public class SpanTest
60+
{
61+
[Params("$data$", "Hej $data$ $count$ $many$", "$den här texten inleds med $data$$data2$")]
62+
public string formatString { get; set; } = "";
63+
public static Foo args = new Foo { data = "Anders" };
64+
65+
[GlobalSetup]
66+
public void GlobalSetup()
67+
{
68+
var dataProvider = new BenchmarkL10nDataProvider();
69+
var l10n = L10n.CreateInstance(new BenchmarkL10nLanguageProvider(), dataProvider, null);
70+
dataProvider.SaveL10n(l10n);
71+
}
72+
73+
[Benchmark]
74+
public void GetPhase()
75+
{
76+
L10n._s(formatString, args);
77+
}
78+
79+
[Benchmark]
80+
public void FormatNamed()
81+
{
82+
L10n.FormatNamed(formatString, args);
83+
}
84+
85+
[Benchmark]
86+
public void GetLanguage()
87+
{
88+
L10n.GetLanguage();
89+
}
90+
}

MN.L10n.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
.gitignore = .gitignore
1313
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
1414
CONTRIBUTING.md = CONTRIBUTING.md
15+
.github\workflows\cs-tests.yml = .github\workflows\cs-tests.yml
1516
.github\workflows\javascripts-tests.yml = .github\workflows\javascripts-tests.yml
1617
LICENSE.txt = LICENSE.txt
1718
README.md = README.md
1819
TROUBLESHOOTING.md = TROUBLESHOOTING.md
19-
.github\workflows\cs-tests.yml = .github\workflows\cs-tests.yml
2020
EndProjectSection
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MN.L10n.Javascript", "MN.L10n.Javascript\MN.L10n.Javascript.csproj", "{C2F42349-0F94-4291-A5E9-62806A3960FA}"
@@ -45,6 +45,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MN.L10n.TestWebApp", "MN.L1
4545
EndProject
4646
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MN.L10n.JavascriptTranslationMiddleware", "MN.L10n.JavascriptTranslationMiddleware\MN.L10n.JavascriptTranslationMiddleware.csproj", "{296F4F0D-4020-486A-8EAE-F77AF23F7AD3}"
4747
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MN.L10n.Benchmark", "MN.L10n.Benchmark\MN.L10n.Benchmark.csproj", "{DB5C45B6-AB84-4C49-8859-F458FAA8ABA0}"
49+
EndProject
4850
Global
4951
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5052
Debug|Any CPU = Debug|Any CPU
@@ -107,6 +109,10 @@ Global
107109
{296F4F0D-4020-486A-8EAE-F77AF23F7AD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
108110
{296F4F0D-4020-486A-8EAE-F77AF23F7AD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
109111
{296F4F0D-4020-486A-8EAE-F77AF23F7AD3}.Release|Any CPU.Build.0 = Release|Any CPU
112+
{DB5C45B6-AB84-4C49-8859-F458FAA8ABA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
113+
{DB5C45B6-AB84-4C49-8859-F458FAA8ABA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
114+
{DB5C45B6-AB84-4C49-8859-F458FAA8ABA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
115+
{DB5C45B6-AB84-4C49-8859-F458FAA8ABA0}.Release|Any CPU.Build.0 = Release|Any CPU
110116
EndGlobalSection
111117
GlobalSection(SolutionProperties) = preSolution
112118
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)