Merge pull request #5 from dcronqvist/benchmarking

Add more benchmarking information and fix paths in benchmarks
This commit is contained in:
dcronqvist 2024-08-14 22:17:40 +02:00 committed by GitHub
commit 50d4f43544
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 14 deletions

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
@ -18,18 +19,24 @@ namespace MyBenchmarks
[HideColumns(["StdDev", "Error", "RatioSD"])] [HideColumns(["StdDev", "Error", "RatioSD"])]
public class MapLoading public class MapLoading
{ {
private string _tmxPath = @"C:\Users\Daniel\winrepos\DotTiled\DotTiled.Tests\Serialization\TestData\Map\empty-map-csv.tmx"; private string _tmxPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmx";
private string _tmxContents = ""; private string _tmxContents = "";
private string _tmjPath = @"C:\Users\Daniel\winrepos\DotTiled\DotTiled.Tests\Serialization\TestData\Map\empty-map-csv.tmj"; private string _tmjPath = @"DotTiled.Tests/Serialization/TestData/Map/default-map/default-map.tmj";
private string _tmjContents = ""; private string _tmjContents = "";
public MapLoading() public MapLoading()
{ {
_tmxContents = System.IO.File.ReadAllText(_tmxPath); var basePath = Path.GetDirectoryName(WhereAmI())!;
_tmjContents = System.IO.File.ReadAllText(_tmjPath); var tmxPath = Path.Combine(basePath, $"../{_tmxPath}");
var tmjPath = Path.Combine(basePath, $"../{_tmjPath}");
_tmxContents = System.IO.File.ReadAllText(tmxPath);
_tmjContents = System.IO.File.ReadAllText(tmjPath);
} }
static string WhereAmI([CallerFilePath] string callerFilePath = "") => callerFilePath;
[BenchmarkCategory("MapFromInMemoryTmxString")] [BenchmarkCategory("MapFromInMemoryTmxString")]
[Benchmark(Baseline = true, Description = "DotTiled")] [Benchmark(Baseline = true, Description = "DotTiled")]
public DotTiled.Map LoadWithDotTiledFromInMemoryTmxString() public DotTiled.Map LoadWithDotTiledFromInMemoryTmxString()
@ -56,6 +63,14 @@ namespace MyBenchmarks
return TiledLib.Map.FromStream(memStream); return TiledLib.Map.FromStream(memStream);
} }
[BenchmarkCategory("MapFromInMemoryTmjString")]
[Benchmark(Description = "TiledLib")]
public TiledLib.Map LoadWithTiledLibFromInMemoryTmjString()
{
using var memStream = new MemoryStream(Encoding.UTF8.GetBytes(_tmjContents));
return TiledLib.Map.FromStream(memStream);
}
[BenchmarkCategory("MapFromInMemoryTmxString")] [BenchmarkCategory("MapFromInMemoryTmxString")]
[Benchmark(Description = "TiledCSPlus")] [Benchmark(Description = "TiledCSPlus")]
public TiledCSPlus.TiledMap LoadWithTiledCSPlusFromInMemoryTmxString() public TiledCSPlus.TiledMap LoadWithTiledCSPlusFromInMemoryTmxString()

View file

@ -18,16 +18,17 @@ Other similar libraries exist, and you may want to consider them for your projec
|**Comparison**|**DotTiled**|[TiledLib](https://github.com/Ragath/TiledLib.Net)|[TiledCSPlus](https://github.com/nolemretaWxd/TiledCSPlus)|[TiledSharp](https://github.com/marshallward/TiledSharp)|[TiledCS](https://github.com/TheBoneJarmer/TiledCS)|[TiledNet](https://github.com/napen123/Tiled.Net)| |**Comparison**|**DotTiled**|[TiledLib](https://github.com/Ragath/TiledLib.Net)|[TiledCSPlus](https://github.com/nolemretaWxd/TiledCSPlus)|[TiledSharp](https://github.com/marshallward/TiledSharp)|[TiledCS](https://github.com/TheBoneJarmer/TiledCS)|[TiledNet](https://github.com/napen123/Tiled.Net)|
|---------------------------------|:-----------------------:|:--------:|:-----------:|:----------:|:-------:|:------:| |---------------------------------|:-----------------------:|:--------:|:-----------:|:----------:|:-------:|:------:|
| Actively maintained | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | | Actively maintained | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Benchmark (time)* | 1.00 | 1.81 | 2.12 | - | - | - | | Benchmark (time)* | 1.00 | 1.83 | 2.16 | - | - | - |
| Benchmark (memory)* | 1.00 | 1.42 | 2.03 | - | - | - | | Benchmark (memory)* | 1.00 | 1.43 | 2.03 | - | - | - |
| .NET Targets | `net8.0`<br>`netstandard2.0` |`net6.0`<br>`net7.0`|`netstandard2.1`|`netstandard2.0`|`netstandard2.0`|`net45`| | .NET Targets | `net8.0` |`net6.0`<br>`net7.0`|`netstandard2.1`|`netstandard2.0`|`netstandard2.0`|`net45`|
| Docs |Usage,<br>XML Docs|Usage|Usage, API,<br>XML Docs|Usage, API|Usage, XML Docs|Usage, XML Docs| | Docs |Usage,<br>XML Docs|Usage|Usage, API,<br>XML Docs|Usage, API|Usage, XML Docs|Usage, XML Docs|
| License | MIT | MIT | MIT | Apache-2.0 | MIT | BSD 3-Clause | | License | MIT | MIT | MIT | Apache-2.0 | MIT | BSD 3-Clause |
| *Feature coverage<br>comparison below*|✅/❌|✅/❌|✅/❌|✅/❌|✅/❌|✅/❌|
> [!NOTE] > [!NOTE]
> *Both benchmark time and memory ratios are relative to DotTiled. Lower is better. Benchmark (time) refers to the execution time of loading the same map from an in-memory string that contains XML data in the `.tmx` format. Benchmark (memory) refers to the memory allocated during that loading process. For further details on the benchmark results, see the collapsible section below. > *Both benchmark time and memory ratios are relative to DotTiled. Lower is better. Benchmark (time) refers to the execution time of loading the same map from an in-memory string that contains XML data in the `.tmx` format. Benchmark (memory) refers to the memory allocated during that loading process. For further details on the benchmark results, see the collapsible section below.
[MonoGame](https://www.monogame.net) users may also want to consider using [MonoGame.Extended](https://github.com/craftworkgames/MonoGame.Extended) for loading Tiled maps and tilesets. Like MonoGame.Extended, DotTiled also provides a way to properly import Tiled maps and tilesets with the MonoGame content pipeline (with the DotTiled.MonoGame.Pipeline NuGet). However, unlike MonoGame.Extended, DotTiled does *not* include any kind of rendering capabilities, and it is up to you as a developer to implement any kind of rendering for your maps when using DotTiled. The feature coverage by MonoGame.Extended is less than that of DotTiled, so you may want to consider using DotTiled if you need access to more Tiled features and flexibility.
<details> <details>
<summary> <summary>
Benchmark details Benchmark details
@ -44,16 +45,17 @@ BenchmarkDotNet v0.13.12, Windows 10 (10.0.19045.4651/22H2/2022Update)
``` ```
| Method | Categories | Mean | Ratio | Gen0 | Gen1 | Allocated | Alloc Ratio | | Method | Categories | Mean | Ratio | Gen0 | Gen1 | Allocated | Alloc Ratio |
|------------ |------------------------- |---------:|------:|-------:|-------:|----------:|------------:| |------------ |------------------------- |---------:|------:|-------:|-------:|----------:|------------:|
| DotTiled | MapFromInMemoryTmjString | 4.292 μs | 1.00 | 0.4349 | - | 5.62 KB | 1.00 | | DotTiled | MapFromInMemoryTmjString | 4.431 μs | 1.00 | 0.4349 | - | 5.58 KB | 1.00 |
| TiledLib | MapFromInMemoryTmjString | 6.369 μs | 1.44 | 0.7019 | 0.0153 | 9.01 KB | 1.61 |
| | | | | | | | | | | | | | | | | |
| DotTiled | MapFromInMemoryTmxString | 3.075 μs | 1.00 | 1.2817 | 0.0610 | 16.4 KB | 1.00 | | DotTiled | MapFromInMemoryTmxString | 3.125 μs | 1.00 | 1.2817 | 0.0610 | 16.36 KB | 1.00 |
| TiledLib | MapFromInMemoryTmxString | 5.574 μs | 1.81 | 1.8005 | 0.0916 | 23.32 KB | 1.42 | | TiledLib | MapFromInMemoryTmxString | 5.709 μs | 1.83 | 1.8005 | 0.0916 | 23.32 KB | 1.43 |
| TiledCSPlus | MapFromInMemoryTmxString | 6.546 μs | 2.13 | 2.5940 | 0.1831 | 33.16 KB | 2.02 | | TiledCSPlus | MapFromInMemoryTmxString | 6.757 μs | 2.16 | 2.5940 | 0.1831 | 33.16 KB | 2.03 |
It is important to note that the above benchmark results come from loading a very small map with a single tile layer as I had to find a common denominator between the libraries so that they all could load the same map. The results aim to be indicative of the performance of the libraries, but should be taken with a grain of salt. Only the actively maintained libraries are included in the benchmark results. TiledCSPlus does not support the `.tmj` format, so it was not included for that benchmark category.
</details> </details>
[MonoGame](https://www.monogame.net) users may also want to consider using [MonoGame.Extended](https://github.com/craftworkgames/MonoGame.Extended) for loading Tiled maps and tilesets. Like MonoGame.Extended, DotTiled also provides a way to properly import Tiled maps and tilesets with the MonoGame content pipeline (with the DotTiled.MonoGame.Pipeline NuGet). However, unlike MonoGame.Extended, DotTiled does *not* include any kind of rendering capabilities, and it is up to you as a developer to implement any kind of rendering for your maps when using DotTiled. The feature coverage by MonoGame.Extended is less than that of DotTiled, so you may want to consider using DotTiled if you need access to more Tiled features and flexibility.
# Feature coverage comparison # Feature coverage comparison
Below is a comparison of the feature coverage of DotTiled and other similar libraries. This comparison is based on the features provided by the Tiled map editor and the support for those features in each library. The comparison is not exhaustive, and you may want to refer to the respective library's documentation or implementation for details. Due to some libraries not having obvious documentation or feature lists, some features may be incorrectly marked as not supported. If you find any inaccuracies, please let me know. Below is a comparison of the feature coverage of DotTiled and other similar libraries. This comparison is based on the features provided by the Tiled map editor and the support for those features in each library. The comparison is not exhaustive, and you may want to refer to the respective library's documentation or implementation for details. Due to some libraries not having obvious documentation or feature lists, some features may be incorrectly marked as not supported. If you find any inaccuracies, please let me know.