Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit 53daebc

Browse files
authored
Add benchmarks
1 parent 8432a92 commit 53daebc

17 files changed

+1077
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Running;
3+
using Slnx;
4+
5+
BenchmarkRunner.Run<ReadBenchmark>();
6+
7+
[MemoryDiagnoser]
8+
public class ReadBenchmark
9+
{
10+
private const string Input = """
11+
<Solution>
12+
<Folder Name="Solution Items">
13+
<File Path="File1.cs" />
14+
<File Path=".editorconfig" />
15+
<Project Path="File.csproj" />
16+
<Folder Name="Test">
17+
<File Path=".editorconfig" />
18+
<File Path="data.cs" />
19+
</Folder>
20+
</Folder>
21+
</Solution>
22+
""";
23+
24+
[Benchmark]
25+
public void Execute()
26+
{
27+
_ = SlnxModel.Load(Input);
28+
}
29+
}
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Slnx.Release\Slnx.Release.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using BenchmarkDotNet.Attributes;
2+
using BenchmarkDotNet.Running;
3+
using Slnx;
4+
5+
BenchmarkRunner.Run<WriteBenchmark>();
6+
7+
[MemoryDiagnoser]
8+
public class WriteBenchmark
9+
{
10+
[Benchmark]
11+
public void Execute()
12+
{
13+
var factory = new SlnxFactory();
14+
15+
var folder = new Folder("Solution Items");
16+
folder.AddProjectWithPathOnly("./CSharp/CSharp.csproj");
17+
folder.AddProjectWithPathOnly("./VB.NET/VB.NET.vbproj");
18+
folder.AddProject(new Project("./DockerCompose/DockerCompose.dcproj", typeGuid: Guid.NewGuid(), config: new(solution: "*|*", project: "*|*|Deploy")));
19+
var moreFolders = new Folder("C++");
20+
moreFolders.AddFiles(["util.cpp", "util.h", "data.cc", "data.h"]);
21+
folder.AddFiles(["File1.cs", "File2.cs"]);
22+
23+
factory.AddFolder(folder);
24+
factory.AddProjectWithPathOnly("Slnx/Slnx.csproj");
25+
factory.AddProjectWithPathOnly("App/App.shproj");
26+
27+
_ = factory.AsModel().Store();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Slnx.Release\Slnx.Release.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace Slnx
2+
{
3+
/// <summary>
4+
/// Represents a "&lt;Configuration&gt;" like tag.
5+
/// </summary>
6+
public class DescendantConfiguration
7+
{
8+
/// <summary>
9+
/// Solution where this configuration applies to.
10+
/// </summary>
11+
public string? Solution { get; init; }
12+
13+
/// <summary>
14+
/// Project where this configuration applies to.
15+
/// </summary>
16+
public string? Project { get; init; }
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="DescendantConfiguration" /> class.
20+
/// </summary>
21+
/// <param name="solution">Solution where this configuration applies to.</param>
22+
/// <param name="project">Project where this configuration applies to.</param>
23+
public DescendantConfiguration(string? solution, string? project)
24+
{
25+
Solution = solution;
26+
Project = project;
27+
}
28+
}
29+
}

benchmark/Slnx.Release/Folder.cs

+260
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
namespace Slnx
2+
{
3+
/// <summary>
4+
/// Represents a folder in the same level as the solution.
5+
/// </summary>
6+
public class Folder
7+
{
8+
/// <summary>
9+
/// Gets an instance of <see cref="Folder" /> with no content and name "(Folder Name)".
10+
/// </summary>
11+
public static Folder Empty => new("(Folder Name)", Array.Empty<Project>(), Array.Empty<Folder>(), Array.Empty<string>());
12+
13+
/// <summary>
14+
/// Name of the folder.
15+
/// </summary>
16+
public string Name { get; set; }
17+
18+
/// <summary>
19+
/// Nested projects in the folder. If this is <see langword="NULL"/>, then there
20+
/// are no descendant projects.
21+
/// </summary>
22+
public List<Project>? DescendantProjects { get; set; }
23+
24+
/// <summary>
25+
/// Nested folders in the folder. If this is <see langword="NULL"/>, then there
26+
/// are no descendant folders.
27+
/// </summary>
28+
public List<Folder>? DescendantFolders { get; set; }
29+
30+
/// <summary>
31+
/// Files in the folder. If this is <see langword="NULL"/>, then there
32+
/// are no descendant files.
33+
/// </summary>
34+
public List<string>? DescendantFiles { get; set; }
35+
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="Folder" /> class.
38+
/// </summary>
39+
/// <param name="name">Folder name.</param>
40+
/// <param name="projects">All projects.</param>
41+
/// <param name="folders">All folders.</param>
42+
/// <param name="files">All files.</param>
43+
public Folder(string name, Project[] projects, Folder[] folders, string[] files)
44+
{
45+
Name = name;
46+
DescendantProjects = projects.Length == 0 ? null : new List<Project>(projects);
47+
DescendantFolders = folders.Length == 0 ? null : new List<Folder>(folders);
48+
DescendantFiles = files.Length == 0 ? null : new List<string>(files);
49+
}
50+
51+
/// <summary>
52+
/// Initializes a new instance of the <see cref="Folder"/> class.
53+
/// </summary>
54+
/// <param name="name">The name of the folder.</param>
55+
/// <remarks>
56+
/// Properties <see cref="DescendantProjects"/>, <see cref="DescendantFiles"/>,
57+
/// and <see cref="DescendantFolders"/> will be <see langword="null"/>.
58+
/// </remarks>
59+
public Folder(string name) : this(name, Array.Empty<Project>(), Array.Empty<Folder>(), Array.Empty<string>())
60+
{
61+
}
62+
63+
/// <summary>
64+
/// Initializes a new instance of the <see cref="Folder"/> class.
65+
/// </summary>
66+
/// <param name="name">The name of the folder.</param>
67+
/// <param name="projects">All projects.</param>
68+
/// <remarks>
69+
/// Properties <see cref="DescendantFiles"/> and <see cref="DescendantFolders"/>
70+
/// will be <see langword="null"/>.
71+
/// </remarks>
72+
public Folder(string name, Project[] projects) : this(name, projects, Array.Empty<Folder>(), Array.Empty<string>())
73+
{
74+
}
75+
76+
/// <summary>
77+
/// Initializes a new instance of the <see cref="Folder"/> class.
78+
/// </summary>
79+
/// <param name="name">The name of the folder.</param>
80+
/// <param name="folders">All folders.</param>
81+
/// <remarks>
82+
/// Properties <see cref="DescendantFiles"/> and <see cref="DescendantProjects"/>
83+
/// will be <see langword="null"/>.
84+
/// </remarks>
85+
public Folder(string name, Folder[] folders) : this(name, Array.Empty<Project>(), folders, Array.Empty<string>())
86+
{
87+
}
88+
89+
/// <summary>
90+
/// Initializes a new instance of the <see cref="Folder"/> class.
91+
/// </summary>
92+
/// <param name="name">The name of the folder.</param>
93+
/// <param name="files">All files.</param>
94+
/// <remarks>
95+
/// Properties <see cref="DescendantProjects"/> and <see cref="DescendantFolders"/>
96+
/// will be <see langword="null"/>.
97+
/// </remarks>
98+
public Folder(string name, string[] files) : this(name, Array.Empty<Project>(), Array.Empty<Folder>(), files)
99+
{
100+
}
101+
102+
/// <summary>
103+
/// Initializes a new instance of the <see cref="Folder"/> class.
104+
/// </summary>
105+
/// <param name="name">The name of the folder.</param>
106+
/// <param name="folders">All folders.</param>
107+
/// <param name="files">All files.</param>
108+
/// <remarks>
109+
/// Property <see cref="DescendantProjects"/> will be <see langword="null"/>.
110+
/// </remarks>
111+
public Folder(string name, Folder[] folders, string[] files) : this(name, Array.Empty<Project>(), folders, files)
112+
{
113+
}
114+
115+
/// <summary>
116+
/// Initializes a new instance of the <see cref="Folder"/> class.
117+
/// </summary>
118+
/// <param name="name">The name of the folder.</param>
119+
/// <param name="folders">All folders.</param>
120+
/// <param name="projects">All projects.</param>
121+
/// <remarks>
122+
/// Property <see cref="DescendantFiles"/> will be <see langword="null"/>.
123+
/// </remarks>
124+
public Folder(string name, Folder[] folders, Project[] projects) : this(name, projects, folders, Array.Empty<string>())
125+
{
126+
}
127+
128+
/// <summary>
129+
/// Initializes a new instance of the <see cref="Folder"/> class.
130+
/// </summary>
131+
/// <param name="name">The name of the folder.</param>
132+
/// <param name="project">All projects.</param>
133+
/// <param name="files">All files.</param>
134+
/// <remarks>
135+
/// Property <see cref="DescendantFolders"/> will be <see langword="null"/>.
136+
/// </remarks>
137+
public Folder(string name, Project[] project, string[] files) : this(name, project, Array.Empty<Folder>(), files)
138+
{
139+
}
140+
141+
/// <summary>
142+
/// Initializes a new instance of the <see cref="Folder"/> class.
143+
/// </summary>
144+
/// <param name="name">The name of the folder.</param>
145+
/// <param name="project">All projects.</param>
146+
/// <param name="folders">All folders.</param>
147+
/// <remarks>
148+
/// Property <see cref="DescendantFiles"/> will be <see langword="null"/>.
149+
/// </remarks>
150+
public Folder(string name, Project[] project, Folder[] folders) : this(name, project, folders, Array.Empty<string>())
151+
{
152+
}
153+
154+
/// <summary>
155+
/// Adds a given array of projects to this instance of <see cref="Folder"/>.
156+
/// </summary>
157+
/// <param name="projects">An array of projects to add.</param>
158+
/// <returns>Current instance of <see cref="Folder"/> after adding the given projects.</returns>
159+
public Folder AddProjects(Project[] projects)
160+
{
161+
DescendantProjects ??= new List<Project>();
162+
163+
foreach (Project project in projects)
164+
{
165+
DescendantProjects.Add(project);
166+
}
167+
168+
return this;
169+
}
170+
171+
/// <summary>
172+
/// Adds a single project to this instance of <see cref="Folder"/>.
173+
/// </summary>
174+
/// <param name="project">A project that will be added.</param>
175+
/// <returns>Current instance of <see cref="Folder"/> after adding the given project.</returns>
176+
public Folder AddProject(Project project)
177+
{
178+
DescendantProjects ??= new List<Project>();
179+
DescendantProjects.Add(project);
180+
return this;
181+
}
182+
183+
/// <summary>
184+
/// Adds a given array of files to this instance of <see cref="Folder"/>.
185+
/// </summary>
186+
/// <param name="files">An array of files to add.</param>
187+
/// <returns>Current instance of <see cref="Folder"/> after adding the given files.</returns>
188+
public Folder AddFiles(string[] files)
189+
{
190+
DescendantFiles ??= new List<string>();
191+
foreach (string file in files)
192+
{
193+
DescendantFiles.Add(file);
194+
}
195+
return this;
196+
}
197+
198+
/// <summary>
199+
/// Adds a single file to this instance of <see cref="Folder"/>.
200+
/// </summary>
201+
/// <param name="file">A file that will be added.</param>
202+
/// <returns>Current instance of <see cref="Folder"/> after adding the given file.</returns>
203+
public Folder AddFile(string file)
204+
{
205+
DescendantFiles ??= new List<string>();
206+
DescendantFiles.Add(file);
207+
return this;
208+
}
209+
210+
/// <summary>
211+
/// Adds a given array of folders to this instance of <see cref="Folder"/>.
212+
/// </summary>
213+
/// <param name="folders">An array of folders to add.</param>
214+
/// <returns>Current instance of <see cref="Folder"/> after adding the given folder.</returns>
215+
public Folder AddFolders(Folder[] folders)
216+
{
217+
DescendantFolders ??= new List<Folder>();
218+
foreach (Folder folder in folders)
219+
{
220+
DescendantFolders.Add(folder);
221+
}
222+
return this;
223+
}
224+
225+
/// <summary>
226+
/// Adds a single folder to this instance of <see cref="Folder"/>.
227+
/// </summary>
228+
/// <param name="folder">A folder that will be added.</param>
229+
/// <returns>Current instance of <see cref="Folder"/> after adding the given folder.</returns>
230+
public Folder AddFolder(Folder folder)
231+
{
232+
DescendantFolders ??= new List<Folder>();
233+
DescendantFolders.Add(folder);
234+
return this;
235+
}
236+
237+
/// <summary>
238+
/// Adds a new project without any configuration to this instance of <see cref="Folder"/>
239+
/// </summary>
240+
/// <param name="path">The path to the project.</param>
241+
/// <returns>
242+
/// A tuple that contains two elements:
243+
/// <list type="bullet">
244+
/// <item>
245+
/// <em>Item 1</em> (<see cref="Folder"/>): Current instance of
246+
/// <see cref="Folder"/> after adding the project.
247+
/// </item>
248+
/// <item>
249+
/// <em>Item 2</em> (<see cref="Project"/>): The project that was added.
250+
/// </item>
251+
/// </list>
252+
/// </returns>
253+
public (Folder, Project) AddProjectWithPathOnly(string path)
254+
{
255+
var project = new Project(path);
256+
AddProject(project);
257+
return (this, project);
258+
}
259+
}
260+
}

0 commit comments

Comments
 (0)