Skip to content

Commit 111b3ab

Browse files
authored
1 parent 52d3cf8 commit 111b3ab

File tree

135 files changed

+18507
-18648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+18507
-18648
lines changed

benchmarks/TestableIO.System.IO.Abstractions.Benchmarks/FileSystemAbstractionBenchmarks.cs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,45 @@
44
using BenchmarkDotNet.Attributes;
55
using BenchmarkDotNet.Order;
66

7-
namespace System.IO.Abstractions.Benchmarks
7+
namespace System.IO.Abstractions.Benchmarks;
8+
9+
//[SimpleJob(launchCount: 3, warmupCount: 10, targetCount: 30)]
10+
[RPlotExporter]
11+
[MemoryDiagnoser]
12+
[Orderer(summaryOrderPolicy: SummaryOrderPolicy.FastestToSlowest)]
13+
[RankColumn]
14+
public class FileSystemAbstractionBenchmarks
815
{
9-
//[SimpleJob(launchCount: 3, warmupCount: 10, targetCount: 30)]
10-
[RPlotExporter]
11-
[MemoryDiagnoser]
12-
[Orderer(summaryOrderPolicy: SummaryOrderPolicy.FastestToSlowest)]
13-
[RankColumn]
14-
public class FileSystemAbstractionBenchmarks
15-
{
16-
#region Members
17-
/// <summary>
18-
/// FileSupport type to avoid counting object initialisation on the benchmark
19-
/// </summary>
20-
private FileSupport _fileSupport;
21-
private DirectorySupport _directorySupport;
22-
#endregion
16+
#region Members
17+
/// <summary>
18+
/// FileSupport type to avoid counting object initialisation on the benchmark
19+
/// </summary>
20+
private FileSupport _fileSupport;
21+
private DirectorySupport _directorySupport;
22+
#endregion
2323

24-
#region CTOR's
25-
public FileSystemAbstractionBenchmarks()
26-
{
27-
// Initialize file support
28-
_fileSupport = new FileSupport();
29-
_directorySupport = new DirectorySupport();
30-
}
31-
#endregion
24+
#region CTOR's
25+
public FileSystemAbstractionBenchmarks()
26+
{
27+
// Initialize file support
28+
_fileSupport = new FileSupport();
29+
_directorySupport = new DirectorySupport();
30+
}
31+
#endregion
3232

33-
#region File IsFile
34-
[Benchmark]
35-
public void FileExists_DotNet() => FileSupportStatic.IsFile(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
33+
#region File IsFile
34+
[Benchmark]
35+
public void FileExists_DotNet() => FileSupportStatic.IsFile(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
3636

37-
[Benchmark]
38-
public void FileExists_Abstraction() => _fileSupport.IsFile(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
39-
#endregion
37+
[Benchmark]
38+
public void FileExists_Abstraction() => _fileSupport.IsFile(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
39+
#endregion
4040

41-
#region Directory Exists
42-
[Benchmark]
43-
public void DirectoryExists_DotNet() => DirectorySupportStatic.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
41+
#region Directory Exists
42+
[Benchmark]
43+
public void DirectoryExists_DotNet() => DirectorySupportStatic.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
4444

45-
[Benchmark]
46-
public void DirectoryExists_Abstraction() => _directorySupport.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
47-
#endregion
48-
}
49-
}
45+
[Benchmark]
46+
public void DirectoryExists_Abstraction() => _directorySupport.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
47+
#endregion
48+
}

benchmarks/TestableIO.System.IO.Abstractions.Benchmarks/MockFileSystemBenchmarks.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@
44
using System.Linq;
55
using XFS = System.IO.Abstractions.TestingHelpers.MockUnixSupport;
66

7-
namespace System.IO.Abstractions.Benchmarks
8-
{
9-
[RPlotExporter]
10-
[MemoryDiagnoser]
11-
public class MockFileSystemBenchmarks
12-
{
13-
private readonly Dictionary<string, MockFileData> testData = CreateTestData();
7+
namespace System.IO.Abstractions.Benchmarks;
148

15-
private static Dictionary<string, MockFileData> CreateTestData()
16-
{
17-
var filesCount = 100000;
18-
var maxDirectoryDepth = 8;
19-
return Enumerable.Range(0, filesCount).ToDictionary(
20-
i => XFS.Path(@$"C:\{string.Join(@"\", Enumerable.Range(0, i % maxDirectoryDepth + 1).Select(i => i.ToString()))}\{i}.bin"),
21-
i => new MockFileData(i.ToString()));
22-
}
9+
[RPlotExporter]
10+
[MemoryDiagnoser]
11+
public class MockFileSystemBenchmarks
12+
{
13+
private readonly Dictionary<string, MockFileData> testData = CreateTestData();
2314

24-
[Benchmark]
25-
public MockFileSystem MockFileSystem_Constructor() => new MockFileSystem(testData);
15+
private static Dictionary<string, MockFileData> CreateTestData()
16+
{
17+
var filesCount = 100000;
18+
var maxDirectoryDepth = 8;
19+
return Enumerable.Range(0, filesCount).ToDictionary(
20+
i => XFS.Path(@$"C:\{string.Join(@"\", Enumerable.Range(0, i % maxDirectoryDepth + 1).Select(i => i.ToString()))}\{i}.bin"),
21+
i => new MockFileData(i.ToString()));
2622
}
27-
}
23+
24+
[Benchmark]
25+
public MockFileSystem MockFileSystem_Constructor() => new MockFileSystem(testData);
26+
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
namespace System.IO.Abstractions.Benchmarks
2-
{
3-
using BenchmarkDotNet.Running;
4-
using System.Reflection;
1+
namespace System.IO.Abstractions.Benchmarks;
2+
3+
using BenchmarkDotNet.Running;
4+
using System.Reflection;
55

6-
class Program
6+
class Program
7+
{
8+
public static void Main(string[] args)
79
{
8-
public static void Main(string[] args)
9-
{
10-
BenchmarkRunner.Run(typeof(Program).Assembly);
11-
}
10+
BenchmarkRunner.Run(typeof(Program).Assembly);
1211
}
13-
}
12+
}

benchmarks/TestableIO.System.IO.Abstractions.Benchmarks/Support/DirectorySupport.cs

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,92 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5-
namespace System.IO.Abstractions.Benchmarks.Support
5+
namespace System.IO.Abstractions.Benchmarks.Support;
6+
7+
public class DirectorySupport
68
{
7-
public class DirectorySupport
9+
#region Members
10+
private IFileSystem _fileSystem;
11+
#endregion
12+
13+
#region CTOR's
14+
public DirectorySupport(IFileSystem fileSystem)
815
{
9-
#region Members
10-
private IFileSystem _fileSystem;
11-
#endregion
16+
_fileSystem = fileSystem;
17+
}
1218

13-
#region CTOR's
14-
public DirectorySupport(IFileSystem fileSystem)
15-
{
16-
_fileSystem = fileSystem;
17-
}
19+
public DirectorySupport() : this(new FileSystem())
20+
{
21+
// Default implementation for FileSystem
22+
}
23+
#endregion
1824

19-
public DirectorySupport() : this(new FileSystem())
20-
{
21-
// Default implementation for FileSystem
22-
}
23-
#endregion
25+
#region Methods
26+
public bool IsDirectory(string path)
27+
{
28+
return _fileSystem.Directory.Exists(path);
29+
}
2430

25-
#region Methods
26-
public bool IsDirectory(string path)
27-
{
28-
return _fileSystem.Directory.Exists(path);
29-
}
31+
private string GetRandomTempDirectory()
32+
{
33+
return Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
34+
}
35+
36+
public string CreateRandomDirectory()
37+
{
38+
var randomPath = this.GetRandomTempDirectory();
39+
_fileSystem.Directory.CreateDirectory(randomPath);
40+
return randomPath;
41+
}
3042

31-
private string GetRandomTempDirectory()
43+
private void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs = true, bool overwrite = true)
44+
{
45+
// Get the subdirectories for the specified directory.
46+
var dir = _fileSystem.DirectoryInfo.New(sourceDirName);
47+
if (!dir.Exists)
3248
{
33-
return Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
49+
throw new DirectoryNotFoundException(
50+
"Source directory does not exist or could not be found: "
51+
+ sourceDirName);
3452
}
3553

36-
public string CreateRandomDirectory()
54+
var dirs = dir.GetDirectories();
55+
// If the destination directory doesn't exist, create it.
56+
if (!_fileSystem.Directory.Exists(destDirName))
3757
{
38-
var randomPath = this.GetRandomTempDirectory();
39-
_fileSystem.Directory.CreateDirectory(randomPath);
40-
return randomPath;
58+
_fileSystem.Directory.CreateDirectory(destDirName);
4159
}
4260

43-
private void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs = true, bool overwrite = true)
61+
// Get the files in the directory and copy them to the new location.
62+
var files = dir.GetFiles();
63+
foreach (var file in files)
4464
{
45-
// Get the subdirectories for the specified directory.
46-
var dir = _fileSystem.DirectoryInfo.New(sourceDirName);
47-
if (!dir.Exists)
48-
{
49-
throw new DirectoryNotFoundException(
50-
"Source directory does not exist or could not be found: "
51-
+ sourceDirName);
52-
}
53-
54-
var dirs = dir.GetDirectories();
55-
// If the destination directory doesn't exist, create it.
56-
if (!_fileSystem.Directory.Exists(destDirName))
57-
{
58-
_fileSystem.Directory.CreateDirectory(destDirName);
59-
}
60-
61-
// Get the files in the directory and copy them to the new location.
62-
var files = dir.GetFiles();
63-
foreach (var file in files)
64-
{
65-
string temppath = Path.Combine(destDirName, file.Name);
66-
file.CopyTo(temppath, overwrite);
67-
}
68-
69-
// If copying subdirectories, copy them and their contents to new location.
70-
if (copySubDirs)
71-
{
72-
foreach (var subdir in dirs)
73-
{
74-
string temppath = Path.Combine(destDirName, subdir.Name);
75-
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
76-
}
77-
}
65+
string temppath = Path.Combine(destDirName, file.Name);
66+
file.CopyTo(temppath, overwrite);
7867
}
7968

80-
public void CreateIfNotExists(string directory)
69+
// If copying subdirectories, copy them and their contents to new location.
70+
if (copySubDirs)
8171
{
82-
if (!_fileSystem.Directory.Exists(directory))
72+
foreach (var subdir in dirs)
8373
{
84-
_fileSystem.Directory.CreateDirectory(directory);
74+
string temppath = Path.Combine(destDirName, subdir.Name);
75+
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
8576
}
8677
}
78+
}
8779

88-
public bool Exists(string directory)
80+
public void CreateIfNotExists(string directory)
81+
{
82+
if (!_fileSystem.Directory.Exists(directory))
8983
{
90-
return _fileSystem.Directory.Exists(directory);
84+
_fileSystem.Directory.CreateDirectory(directory);
9185
}
92-
#endregion
9386
}
94-
}
87+
88+
public bool Exists(string directory)
89+
{
90+
return _fileSystem.Directory.Exists(directory);
91+
}
92+
#endregion
93+
}

0 commit comments

Comments
 (0)