-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Processing dotnet/runtime#123041 (comment) command:
Command
-amd -intel -arm
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);
[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
[MemoryDiagnoser(false)]
public partial class Tests
{
private string _directoryPath;
[GlobalSetup]
public void Setup()
{
_directoryPath = Path.GetTempFileName();
File.Delete(_directoryPath);
Directory.CreateDirectory(_directoryPath);
for (int i = 0; i < 10_000; i++)
{
File.Create(Path.Combine(_directoryPath, $"file{i}.txt")).Dispose();
}
}
[Benchmark]
public int Sum1()
{
int sum = 0;
foreach (string path in Directory.EnumerateFiles(_directoryPath)) sum += path.Length;
return sum;
}
[Benchmark]
public int Sum2()
{
int sum = 0;
foreach (string path in Directory.EnumerateFiles(_directoryPath, "file*")) sum += path.Length;
return sum;
}
[Benchmark]
public int Sum3()
{
int sum = 0;
foreach (string path in Directory.EnumerateFiles(_directoryPath, "*.txt")) sum += path.Length;
return sum;
}
[Benchmark]
public int Sum4()
{
int sum = 0;
foreach (string path in Directory.EnumerateFiles(_directoryPath, "*12*")) sum += path.Length;
return sum;
}
[GlobalCleanup]
public void Cleanup()
{
Directory.Delete(_directoryPath, true);
}
}
(EgorBot will reply in this issue)
Metadata
Metadata
Assignees
Labels
No labels