Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0ce0f2a

Browse files
authored
Add char.ToLower/Upper perf tests (#28765)
1 parent fd239bc commit 0ce0f2a

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

src/System.Runtime/tests/Performance/Perf.Char.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,63 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Collections.Generic;
6+
using System.Globalization;
57
using Microsoft.Xunit.Performance;
8+
using Xunit;
69

710
namespace System.Tests
811
{
912
public class Perf_Char
1013
{
11-
[Benchmark]
12-
public static char Char_ToLower()
14+
private const int InnerIterations = 1_000_000;
15+
16+
public static IEnumerable<object[]> Char_ChangeCase_MemberData()
17+
{
18+
yield return new object[] { 'A', "en-US" }; // ASCII upper case
19+
yield return new object[] { 'a', "en-US" }; // ASCII lower case
20+
yield return new object[] { '\u0130', "en-US" }; // non-ASCII, English
21+
yield return new object[] { '\u4F60', "zh-Hans" }; // non-ASCII, Chinese
22+
}
23+
24+
[Benchmark(InnerIterationCount = InnerIterations)]
25+
[MemberData(nameof(Char_ChangeCase_MemberData))]
26+
public static char Char_ToLower(char c, string cultureName)
27+
{
28+
char ret = default(char);
29+
CultureInfo culture = new CultureInfo(cultureName);
30+
31+
foreach (var iteration in Benchmark.Iterations)
32+
{
33+
using (iteration.StartMeasurement())
34+
{
35+
for (int i = 0; i < InnerIterations; i++)
36+
{
37+
ret = Char.ToLower(c, culture);
38+
}
39+
}
40+
}
41+
42+
return ret;
43+
}
44+
45+
[Benchmark(InnerIterationCount = InnerIterations)]
46+
[MemberData(nameof(Char_ChangeCase_MemberData))]
47+
public static char Char_ToUpper(char c, string cultureName)
1348
{
1449
char ret = default(char);
50+
CultureInfo culture = new CultureInfo(cultureName);
1551

1652
foreach (var iteration in Benchmark.Iterations)
53+
{
1754
using (iteration.StartMeasurement())
18-
ret = Char.ToLower('A');
55+
{
56+
for (int i = 0; i < InnerIterations; i++)
57+
{
58+
ret = Char.ToUpper(c, culture);
59+
}
60+
}
61+
}
1962

2063
return ret;
2164
}

0 commit comments

Comments
 (0)