mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-05-09 02:26:02 +03:00
Added Tmj parsing to benchmarking
This commit is contained in:
parent
bb74d3ccee
commit
cc57b172a8
6 changed files with 112 additions and 101 deletions
|
@ -15,68 +15,54 @@ namespace MyBenchmarks
|
|||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
|
||||
[CategoriesColumn]
|
||||
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
|
||||
[HideColumns(["StdDev", "Error", "RatioSD"])]
|
||||
public class MapLoading
|
||||
{
|
||||
private string _tmxPath = @"C:\Users\Daniel\winrepos\DotTiled\DotTiled.Tests\Serialization\Tmx\TestData\Map\empty-map-csv.tmx";
|
||||
private string _tmxPath = @"C:\Users\Daniel\winrepos\DotTiled\DotTiled.Tests\Serialization\TestData\Map\empty-map-csv.tmx";
|
||||
private string _tmxContents = "";
|
||||
|
||||
private string _tmjPath = @"C:\Users\Daniel\winrepos\DotTiled\DotTiled.Tests\Serialization\TestData\Map\empty-map-csv.tmj";
|
||||
private string _tmjContents = "";
|
||||
|
||||
public MapLoading()
|
||||
{
|
||||
_tmxContents = System.IO.File.ReadAllText(_tmxPath);
|
||||
_tmjContents = System.IO.File.ReadAllText(_tmjPath);
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Baseline = true, Description = "DotTiled")]
|
||||
public DotTiled.Map LoadWithDotTiledFromInMemoryString()
|
||||
public DotTiled.Map LoadWithDotTiledFromInMemoryTmxString()
|
||||
{
|
||||
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());
|
||||
using var mapReader = new DotTiled.TmxMapReader(xmlReader, _ => throw new Exception(), _ => throw new Exception(), []);
|
||||
return mapReader.ReadMap();
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromTmxFile")]
|
||||
[BenchmarkCategory("MapFromInMemoryTmjString")]
|
||||
[Benchmark(Baseline = true, Description = "DotTiled")]
|
||||
public DotTiled.Map LoadWithDotTiledFromFile()
|
||||
public DotTiled.Map LoadWithDotTiledFromInMemoryTmjString()
|
||||
{
|
||||
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());
|
||||
using var mapReader = new DotTiled.TmjMapReader(_tmjContents, _ => throw new Exception(), _ => throw new Exception(), []);
|
||||
return mapReader.ReadMap();
|
||||
}
|
||||
|
||||
[BenchmarkCategory("MapFromInMemoryTmxString")]
|
||||
[Benchmark(Description = "TiledLib")]
|
||||
public TiledLib.Map LoadWithTiledLibFromInMemoryString()
|
||||
public TiledLib.Map LoadWithTiledLibFromInMemoryTmxString()
|
||||
{
|
||||
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()
|
||||
public TiledCSPlus.TiledMap LoadWithTiledCSPlusFromInMemoryTmxString()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public class Program
|
||||
|
@ -84,6 +70,7 @@ namespace MyBenchmarks
|
|||
public static void Main(string[] args)
|
||||
{
|
||||
var config = BenchmarkDotNet.Configs.DefaultConfig.Instance
|
||||
.WithArtifactsPath(args[0])
|
||||
.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