Skip to content

Commit

Permalink
disable task wait warnings in benchmark code
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Aug 29, 2024
1 parent 4baa679 commit 812eeeb
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/SIL.Harmony.Tests/DataModelPerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void StopTrace()

private static async Task<TimeSpan> MeasureTime(Func<Task> action, int iterations = 10)
{
TimeSpan total = TimeSpan.Zero;
var total = TimeSpan.Zero;
for (var i = 0; i < iterations; i++)
{
var start = Stopwatch.GetTimestamp();
Expand All @@ -74,7 +74,7 @@ private static async Task<TimeSpan> MeasureTime(Func<Task> action, int iteration
public async Task SimpleAddChangePerformanceTest()
{
//disable validation because it's slow
var dataModelTest = new DataModelTestBase(false, alwaysValidate: false);
var dataModelTest = new DataModelTestBase(alwaysValidate: false);
// warmup the code, this causes jit to run and keeps our actual test below consistent
await dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity 0"));
var runtimeAddChange1Snapshot = await MeasureTime(() => dataModelTest.WriteNextChange(dataModelTest.SetWord(Guid.NewGuid(), "entity 1")).AsTask());
Expand Down Expand Up @@ -131,51 +131,50 @@ private class XUnitBenchmarkLogger(ITestOutputHelper output) : ILogger
{
public string Id => nameof(XUnitBenchmarkLogger);
public int Priority => 0;
private StringBuilder? sb;
private StringBuilder? _sb;

public void Write(LogKind logKind, string text)
{
if (sb == null)
{
sb = new StringBuilder();
}
_sb ??= new StringBuilder();

sb.Append(text);
_sb.Append(text);
}

public void WriteLine()
{
if (sb is not null)
if (_sb is not null)
{
output.WriteLine(sb.ToString());
sb.Clear();
output.WriteLine(_sb.ToString());
_sb.Clear();
}
else
output.WriteLine(string.Empty);
}

public void WriteLine(LogKind logKind, string text)
{
if (sb is not null)
if (_sb is not null)
{
output.WriteLine(sb.Append(text).ToString());
sb.Clear();
output.WriteLine(_sb.Append(text).ToString());
_sb.Clear();
}
else
output.WriteLine(text);
}

public void Flush()
{
if (sb is not null)
if (_sb is not null)
{
output.WriteLine(sb.ToString());
sb.Clear();
output.WriteLine(_sb.ToString());
_sb.Clear();
}
}
}
}

// disable warning about waiting for sync code, benchmarkdotnet does not support async code, and it doesn't deadlock when waiting.
#pragma warning disable VSTHRD002
[SimpleJob(RunStrategy.Throughput, warmupCount: 2)]
public class DataModelPerformanceBenchmarks
{
Expand Down Expand Up @@ -229,4 +228,5 @@ public void GlobalCleanup()
{
_templateModel.DisposeAsync().GetAwaiter().GetResult();
}
}
}
#pragma warning restore VSTHRD002

0 comments on commit 812eeeb

Please sign in to comment.