From 7df7afb0a487b0abde9e1c0ffdfd1d7fb457360b Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Wed, 19 Jan 2022 10:50:00 +0100 Subject: [PATCH] add benchmarks for File.ReadAllLines* methods --- .../libraries/System.IO.FileSystem/Perf.File.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/benchmarks/micro/libraries/System.IO.FileSystem/Perf.File.cs b/src/benchmarks/micro/libraries/System.IO.FileSystem/Perf.File.cs index 859da2eb2d2..6b37f31dec2 100644 --- a/src/benchmarks/micro/libraries/System.IO.FileSystem/Perf.File.cs +++ b/src/benchmarks/micro/libraries/System.IO.FileSystem/Perf.File.cs @@ -143,6 +143,19 @@ public void CleanupReadAllBytes() public Task ReadAllBytesAsync(int size) => File.ReadAllBytesAsync(_filesToRead[size]); #endif + [GlobalSetup(Targets = new[] { nameof(ReadAllLines), "ReadAllLinesAsync" })] + public void SetupReadAllLines() + => File.WriteAllLines(_testFilePath = FileUtils.GetTestFilePath(), ValuesGenerator.ArrayOfStrings(count: 100, minLength: 20, maxLength: 80)); + + [Benchmark] + public string[] ReadAllLines() => File.ReadAllLines(_testFilePath); + +#if !NETFRAMEWORK + [BenchmarkCategory(Categories.NoWASM)] + [Benchmark] + public Task ReadAllLinesAsync() => File.ReadAllLinesAsync(_testFilePath); +#endif + [GlobalSetup(Targets = new[] { nameof(AppendAllLines), "AppendAllLinesAsync" })] public void SetupAppendAllLines() {