Files
ParadoxSaveParser/ParadoxSaveParser.Benchmarks/ParserInputBenchmarks.cs
T
2026-09-15 13:18:09 +02:00

30 lines
1.0 KiB
C#

using System.IO;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using ParadoxSaveParser.Lib;
namespace ParadoxSaveParser.Benchmarks;
/// <summary>
/// SearchExpression only, parsing straight from the save file on disk:
/// the file is opened inside the benchmark and is never preloaded into a byte[].
/// Run it once with and once without the internal <c>MemoryStream</c> copy in
/// <see cref="SaveParserEU4" /> to see what that copy buys.
/// </summary>
[MemoryDiagnoser]
[SimpleJob(RunStrategy.Monitoring, launchCount: 1, warmupCount: 1, iterationCount: 5)]
public class ParserInputBenchmarks
{
private SearchExpressionCompilation _query = null!;
[GlobalSetup]
public void Setup() => _query = new SearchExpressionCompilation(BenchData.PdxQuery);
[Benchmark(Description = "SearchExpression over FileStream")]
public long FromFile()
{
using var file = File.OpenRead(BenchData.PdxPath);
return Extractors.SearchExpressionFromStream(file, _query);
}
}