Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/benchmarks/micro/MicroBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<None Update="libraries\System.IO.Compression\TestData\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="libraries\System.Runtime\TestData\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="libraries\System.Text.RegularExpressions\TestData\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
43 changes: 43 additions & 0 deletions src/benchmarks/micro/libraries/System.Runtime/Perf.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
Expand Down Expand Up @@ -292,6 +293,48 @@ public int IndexerCheckPathLength()
return counter;
}

// Retrieved from https://data.cms.gov/sites/default/files/2024-05/b492c960-aea2-4f4e-a5f6-258c726b1a58/TMEDTREND_PUBLIC_240528.csv on Jan 22, 2025
private static readonly Lazy<string[]> s_csvShortText = new Lazy<string[]>(() => ReadInputFile("TMEDTREND_PUBLIC_240528.csv"));
// Retrieved from https://data.transportation.gov/api/views/kbvr-tyu5/rows.csv on Jan 22, 2025
private static readonly Lazy<string[]> s_csvShortMixed = new Lazy<string[]>(() => ReadInputFile("motor_fuel_sales.csv"));
// Retrieved from https://www.census.gov/econ/bfs/csv/date_table.csv on Jan 22, 2025
private static readonly Lazy<string[]> s_csvShortDates = new Lazy<string[]>(() => ReadInputFile("date_table.csv"));
// Retrieved from https://www.usda.gov/sites/default/files/documents/ai_inventory.csv on Jan 22, 2025
private static readonly Lazy<string[]> s_csvLongText = new Lazy<string[]>(() => ReadInputFile("ai_inventory.csv"));
// Retrieved from https://www.epa.gov/sites/production/files/2014-05/tri_2012_nd.csv on Jan 22, 2025
private static readonly Lazy<string[]> s_csvLongMixed = new Lazy<string[]>(() => ReadInputFile("tri_2012_nd.csv"));
// Retrieved from https://data.cdc.gov/api/views/dxpw-cm5u/rows.csv on Jan 22, 2025
private static readonly Lazy<string[]> s_csvLongNumbers = new Lazy<string[]>(() => ReadInputFile("500_cities.csv"));
private static volatile int s_splitCsvFieldCount;

public static IEnumerable<object[]> CsvCorpus()
{
yield return new object[] { "Short Text", s_csvShortText.Value };
yield return new object[] { "Short Mixed", s_csvShortMixed.Value };
yield return new object[] { "Short Dates", s_csvShortDates.Value };
yield return new object[] { "Long Text", s_csvLongText.Value };
yield return new object[] { "Long Mixed", s_csvLongMixed.Value };
yield return new object[] { "Long Numbers", s_csvLongNumbers.Value };
}

public static string[] ReadInputFile(string name)
=> File.ReadAllLines(Path.Combine(AppContext.BaseDirectory, "libraries", "System.Runtime", "TestData", name));

Comment thread
danmoseley marked this conversation as resolved.
[Benchmark]
[ArgumentsSource(nameof(CsvCorpus))]
public string[] Split_Csv(string testName, string[] lines)
{
string[] split = null;
int fieldCount = 0;
for (int i = 0; i < lines.Length; i++)
{
split = lines[i].Split(',');
fieldCount ^= split.Length;
}
s_splitCsvFieldCount = fieldCount;
Comment thread
danmoseley marked this conversation as resolved.
return split;
Comment thread
danmoseley marked this conversation as resolved.
Comment thread
danmoseley marked this conversation as resolved.
}

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static char getStringCharNoInline(string str, int index)
{
Expand Down
501 changes: 501 additions & 0 deletions src/benchmarks/micro/libraries/System.Runtime/TestData/500_cities.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
The CSV files in this directory are sourced from public U.S. government
data portals and are in the public domain under U.S. law (17 U.S.C. § 105).

TMEDTREND_PUBLIC_240528.csv
Source: https://data.cms.gov/sites/default/files/2024-05/b492c960-aea2-4f4e-a5f6-258c726b1a58/TMEDTREND_PUBLIC_240528.csv
Retrieved: January 22, 2025
Provider: Centers for Medicare & Medicaid Services (CMS)

motor_fuel_sales.csv
Source: https://data.transportation.gov/api/views/kbvr-tyu5/rows.csv
Original name: Monthly Motor Fuel Sales Reported by States, Selected Data from FHWA Monthly Motor Fuel Report
Retrieved: January 22, 2025
Provider: U.S. Department of Transportation

date_table.csv
Source: https://www.census.gov/econ/bfs/csv/date_table.csv
Retrieved: January 22, 2025
Provider: U.S. Census Bureau

ai_inventory.csv
Source: https://www.usda.gov/sites/default/files/documents/ai_inventory.csv
Retrieved: January 22, 2025
Provider: U.S. Department of Agriculture (USDA)

tri_2012_nd.csv
Source: https://www.epa.gov/sites/production/files/2014-05/tri_2012_nd.csv
Retrieved: January 22, 2025
Provider: U.S. Environmental Protection Agency (EPA)

500_cities.csv
Source: https://data.cdc.gov/api/views/dxpw-cm5u/rows.csv
Original name: 500 Cities: City-level Data (GIS Friendly Format), 2019 release
Retrieved: January 22, 2025
Provider: Centers for Disease Control and Prevention (CDC)
Loading