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

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
winscripter authored Oct 13, 2024
1 parent ab551fd commit 0554305
Showing 1 changed file with 60 additions and 71 deletions.
131 changes: 60 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ File1.cs
.editorconfig
```

### Writing (applies to Slnx 2.0, see below code block for Slnx 3.0)
### Writing (applies to Slnx 3.0)
```cs
using Slnx;
using System.Text.Json;
Expand All @@ -57,6 +57,7 @@ folder.AddProject(new Project("./DockerCompose/DockerCompose.dcproj", typeGuid:
var moreFolders = new Folder("C++");
moreFolders.AddFiles(["util.cpp", "util.h", "data.cc", "data.h"]);
folder.AddFiles(["File1.cs", "File2.cs"]);
folder.AddFolder(moreFolders);

factory.AddFolder(folder);
factory.AddProjectWithPathOnly("Slnx/Slnx.csproj");
Expand All @@ -69,58 +70,8 @@ File.AppendAllText("OutputSlnx.txt", content);
var model = SlnxModel.Load(File.ReadAllText("OutputSlnx.txt"));
Console.WriteLine(JsonSerializer.Serialize(model));
```
#### For Slnx 3.0
Note: The constructor of the `Project` class was slightly changed in Slnx 3.0. Change this:
```cs
// ...
folder.AddProject(new Project("./DockerCompose/DockerCompose.dcproj", typeGuid: Guid.NewGuid(), config: new(solution: "*|*", project: "*|*|Deploy")));
var moreFolders = new Folder("C++");
```
to:
```cs
// ...
folder.AddProject(new Project("./DockerCompose/DockerCompose.dcproj", /*HERE -->*/type: Guid.NewGuid().ToString(), /*<-- HERE*/ config: new(solution: "*|*", project: "*|*|Deploy")));
var moreFolders = new Folder("C++");
```
The program will generate a file named `OutputSlnx.txt` with these contents:

Starting with Slnx 3.0, you can convert `SlnxModel` to `string` asynchronously:
```cs
// ...
factory.AddProjectWithPathOnly("App/App.shproj");

string content = await factory.AsModel().StoreAsync(); // <---
File.AppendAllText("OutputSlnx.txt", content);
```

### Writing (applies to Slnx 1.0)
```cs
using Slnx;

var factory = new SlnxFactory();
factory.Folders.Add(new Folder("Solution Items", new[]
{
new Project("./CSharp/CSharp.csproj"),
new Project("./VB.NET/VB.NET.vbproj"),
new Project("./DockerCompose/DockerCompose.dcproj", Guid.NewGuid(), new(solution: "*|*", project: "*|*|Deploy"))
}, new[]
{
new Folder("C++", Array.Empty<Project>(), Array.Empty<Folder>(), new[]
{
"util.cpp",
"util.h",
"data.cc",
"data.h"
})
}, new string[] { "File1.cs", "File2.cs" }));

factory.Projects.Add(new Project("Slnx/Slnx.csproj"));
factory.Projects.Add(new Project("App/App.shproj"));

var model = factory.AsModel();
model.Store("OutputSlnx.txt");
```

Both of these programs will generate `OutputSlnx.txt` with the following contents:
```
<Solution>
<Project Path="Slnx/Slnx.csproj" />
Expand All @@ -144,40 +95,78 @@ Both of these programs will generate `OutputSlnx.txt` with the following content
```

# Contributing
Bug reports, suggestions, questions and other feedback are welcome.
Bug reports, feature suggestions, questions, and other feedback are welcome.

# Compatibility
Slnx uses the .NET 6.0 Runtime, but it works fine for preceding versions, including .NET 7.0, 8.0, and future releases.

# Benchmarking
This is the benchmark for SLNX version 2.0, using `BenchmarkDotNet`. Benchmarks are found in the `./benchmark` folder.
### Read

## Read Benchmark
Input:
```xml
<Solution>
<Folder Name="Solution Items">
<File Path="File1.cs" />
<File Path=".editorconfig" />
<Project Path="File.csproj" />
<Folder Name="Test">
<File Path=".editorconfig" />
<File Path="data.cs" />
</Folder>
</Folder>
</Solution>
```

BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
Benchmark result:
```
BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
AMD Ryzen 7 4700U with Radeon Graphics, 1 CPU, 8 logical and 8 physical cores
.NET SDK 8.0.204
[Host] : .NET 8.0.4 (8.0.424.16909), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.4 (8.0.424.16909), X64 RyuJIT AVX2
.NET SDK 8.0.303
[Host] : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
```
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|------------ |---------:|----------:|----------:|-------:|----------:|
| ReadBenchie | 4.486 μs | 0.0301 μs | 0.0267 μs | 7.1106 | 14.55 KB |

## Write Benchmark
Code:
```cs
var factory = new SlnxFactory();

var folder = new Folder("Solution Items");
folder.AddProjectWithPathOnly("./CSharp/CSharp.csproj");
folder.AddProjectWithPathOnly("./VB.NET/VB.NET.vbproj");
folder.AddProject(new Project("./DockerCompose/DockerCompose.dcproj", type: null, config: new(solution: "*|*", project: "*|*|Deploy")));
var moreFolders = new Folder("C++");
moreFolders.AddFiles(["util.cpp", "util.h", "data.cc", "data.h"]);
folder.AddFiles(["File1.cs", "File2.cs"]);
folder.AddFolder(moreFolders);

factory.AddFolder(folder);
factory.AddProjectWithPathOnly("Slnx/Slnx.csproj");
factory.AddProjectWithPathOnly("App/App.shproj");

_ = factory.AsModel().Store();
```
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|-------- |---------:|----------:|----------:|-------:|----------:|
| Execute | 4.469 μs | 0.0834 μs | 0.0739 μs | 6.8970 | 14.17 KB |
To provide the accurate benchmark, we're not saving or logging the result anywhere like console or file - we're
just focusing on how fast Slnx can export the SlnxFactory instance as a string.

### Write
Benchmark result:
```
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.2861/23H2/2023Update/SunValley3)
AMD Ryzen 7 4700U with Radeon Graphics, 1 CPU, 8 logical and 8 physical cores
.NET SDK 8.0.204
[Host] : .NET 8.0.4 (8.0.424.16909), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.4 (8.0.424.16909), X64 RyuJIT AVX2
.NET SDK 8.0.303
[Host] : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
```
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|-------- |---------:|----------:|----------:|--------:|----------:|
| Execute | 8.763 μs | 0.1065 μs | 0.0944 μs | 17.6392 | 36.2 KB |

| Method | Mean | Error | StdDev | Gen0 | Allocated |
|------------- |---------:|----------:|----------:|-------:|----------:|
| WriteBenchie | 4.841 μs | 0.0371 μs | 0.0310 μs | 9.4299 | 19.33 KB |

0 comments on commit 0554305

Please sign in to comment.