mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-09 02:46:04 +03:00
Some benchmarking and README updates
This commit is contained in:
parent
bafbd3d6c7
commit
3e8f3fbfb9
3 changed files with 98 additions and 75 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
|
||||
<PackageReference Include="TiledCSPlus" Version="4.2.0" />
|
||||
<PackageReference Include="TiledLib" Version="4.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,26 +1,81 @@
|
|||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Order;
|
||||
using BenchmarkDotNet.Reports;
|
||||
using BenchmarkDotNet.Running;
|
||||
|
||||
namespace MyBenchmarks
|
||||
{
|
||||
public class MapLoader
|
||||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
|
||||
[CategoriesColumn]
|
||||
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
|
||||
public class MapLoading
|
||||
{
|
||||
public MapLoader()
|
||||
private string _tmxPath = @"C:\Users\Daniel\winrepos\DotTiled\DotTiled.Tests\Serialization\Tmx\TestData\Map\empty-map-csv.tmx";
|
||||
private string _tmxContents = "";
|
||||
|
||||
public MapLoading()
|
||||
{
|
||||
_tmxContents = System.IO.File.ReadAllText(_tmxPath);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public DotTiled.Map LoadWithDotTiled()
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Baseline = true, Description = "DotTiled")]
|
||||
public DotTiled.Map LoadWithDotTiledFromInMemoryString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var stringReader = new StringReader(_tmxContents);
|
||||
using var xmlReader = XmlReader.Create(stringReader);
|
||||
using var mapReader = new DotTiled.TmxMapReader(xmlReader, _ => throw new Exception(), _ => throw new Exception());
|
||||
return mapReader.ReadMap();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public TiledLib.Map LoadWithTiledLib()
|
||||
[BenchmarkCategory("MapFromTmxFile")]
|
||||
[Benchmark(Baseline = true, Description = "DotTiled")]
|
||||
public DotTiled.Map LoadWithDotTiledFromFile()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var fileStream = System.IO.File.OpenRead(_tmxPath);
|
||||
using var xmlReader = XmlReader.Create(fileStream);
|
||||
using var mapReader = new DotTiled.TmxMapReader(xmlReader, _ => throw new Exception(), _ => throw new Exception());
|
||||
return mapReader.ReadMap();
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Description = "TiledLib")]
|
||||
public TiledLib.Map LoadWithTiledLibFromInMemoryString()
|
||||
{
|
||||
using var memStream = new MemoryStream(Encoding.UTF8.GetBytes(_tmxContents));
|
||||
return TiledLib.Map.FromStream(memStream);
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromTmxFile")]
|
||||
[Benchmark(Description = "TiledLib")]
|
||||
public TiledLib.Map LoadWithTiledLibFromFile()
|
||||
{
|
||||
using var fileStream = System.IO.File.OpenRead(_tmxPath);
|
||||
var map = TiledLib.Map.FromStream(fileStream);
|
||||
return map;
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Description = "TiledCSPlus")]
|
||||
public TiledCSPlus.TiledMap LoadWithTiledCSPlusFromInMemoryString()
|
||||
{
|
||||
using var memStream = new MemoryStream(Encoding.UTF8.GetBytes(_tmxContents));
|
||||
return new TiledCSPlus.TiledMap(memStream);
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromTmxFile")]
|
||||
[Benchmark(Description = "TiledCSPlus")]
|
||||
public TiledCSPlus.TiledMap LoadWithTiledCSPlusFromFile()
|
||||
{
|
||||
using var fileStream = System.IO.File.OpenRead(_tmxPath);
|
||||
return new TiledCSPlus.TiledMap(fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +83,10 @@ namespace MyBenchmarks
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
//var summary = BenchmarkRunner.Run<Md5VsSha256>();
|
||||
var config = BenchmarkDotNet.Configs.DefaultConfig.Instance
|
||||
.WithOptions(ConfigOptions.DisableOptimizationsValidator)
|
||||
.AddDiagnoser(BenchmarkDotNet.Diagnosers.MemoryDiagnoser.Default);
|
||||
var summary = BenchmarkRunner.Run<MapLoading>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue