-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBenchmarks.Constructor.cs
33 lines (28 loc) · 1.11 KB
/
Benchmarks.Constructor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Abstractions;
using System.Linq;
using Testably.Abstractions.Testing;
using Testably.Abstractions.Testing.Initializer;
using MockFileSystem = Testably.Abstractions.Testing.MockFileSystem;
namespace Testably.Abstractions.Benchmarks;
public partial class Benchmarks
{
private readonly Dictionary<string, string> _testData = CreateTestData();
[Benchmark]
public IFileSystem ConstructorEmpty_Testably() => new MockFileSystem();
[Benchmark]
public IFileSystem ConstructorWithInitialization_1000_Testably() => new MockFileSystem()
.Initialize()
.With(_testData.Select(x => new FileDescription(x.Key, x.Value)).ToArray()).FileSystem;
private static Dictionary<string, string> CreateTestData()
{
int filesCount = 1000;
int maxDirectoryDepth = 8;
return Enumerable.Range(0, filesCount)
.ToDictionary(
i => @$"C:\{string.Join(@"\", Enumerable.Range(0, (i % maxDirectoryDepth) + 1).Select(j => j.ToString(CultureInfo.InvariantCulture)))}\{i}.bin",
i => i.ToString(CultureInfo.InvariantCulture));
}
}