dotnet / dotnet/BenchmarkDotNet

v0.13.5: GlobalCleanup Console.WriteLine output messed within //AfterActualRun area (fine in 0.13.2)

Open
#2,294 6 comments 0 reactions 1 assignee Claimed by @adamsitnik View on GitHub
Dominant language
C#
Stars
11.5k
Forks
1.1k
Avg merge
6d 11h
Merged PRs (30d)
12

Description

Hi there,

today I updated from 0.13.2 to the latest version 0.13.5 and recognized that my `Console.WriteLine` outputs are now messed up within the `//AfterActualRun` output area of the log file.

Not sure what exactly is going on, I haven't changed my benchmarks or outputs lately... unfortunately I can't upgrade to the latest version with this issue and hope you can help with this issue. Seems version 0.13.3 introduced this new behavior.

![image](https://github.com/dotnet/BenchmarkDotNet/assets/37984366/2cec0c05-dded-46ef-ae81-6dee243eaa35)

Log-Files from tests of different versions:
- v0.13.5 --> [BenchmarkDotNetOutputBug.Benchmarks-20230508-084211.log](https://github.com/dotnet/BenchmarkDotNet/files/11418673/BenchmarkDotNetOutputBug.Benchmarks-20230508-084211.log)
- v0.13.4 --> [BenchmarkDotNetOutputBug.Benchmarks-20230508-084553.log](https://github.com/dotnet/BenchmarkDotNet/files/11418674/BenchmarkDotNetOutputBug.Benchmarks-20230508-084553.log)
- v0.13.3 --> [BenchmarkDotNetOutputBug.Benchmarks-20230508-084837.log](https://github.com/dotnet/BenchmarkDotNet/files/11418675/BenchmarkDotNetOutputBug.Benchmarks-20230508-084837.log)
- v0.13.2 --> [BenchmarkDotNetOutputBug.Benchmarks-20230508-085341.log](https://github.com/dotnet/BenchmarkDotNet/files/11418676/BenchmarkDotNetOutputBug.Benchmarks-20230508-085341.log)

Here an example project to reproduce the behavior: [BenchmarkDotNetOutputBug.zip](https://github.com/dotnet/BenchmarkDotNet/files/11418738/BenchmarkDotNetOutputBug.zip)

```c#
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using System.Text;

namespace BenchmarkDotNetOutputBug
{
public class BenchmarksRunner
{
public const string BenchmarkProjectName = "BenchmarkDotNetOutputBug";
public static readonly string BenchmarkArtifactsRootPath =
Path.Combine(
Path.GetFullPath(
DefaultConfig.Instance.ArtifactsPath + "/../../../../../"
+ BenchmarkProjectName
), "BenchmarkDotNet.Artifacts"
);

public static void Main()
{
ManualConfig customConfig = DefaultConfig.Instance
.WithArtifactsPath(BenchmarkArtifactsRootPath);
_ = BenchmarkDotNet.Running.BenchmarkRunner
.Run(typeof(Benchmarks).Assembly, customConfig);
}
}

public class Benchmarks
{
private long _result = 0;
private int _loopCount = 0;

[Params(10, 25, 50)]
public int _count = 0;

private string GetOutput()
{
return new StringBuilder()
.Append("Pseudo stats:").Append('\n')
.Append('\t').Append("- _loopCount: ").Append(_loopCount).Append('\n')
.Append('\t').Append("- _result: ").Append(_result)
.ToString();
}

[GlobalCleanup]
public void Cleanup()
{
Console.WriteLine(GetOutput());
}

[GlobalSetup]
public void Setup()
{
_loopCount = _count;
}

[Benchmark]
public double MyBenchmark()
{
for (int i = 0; i < _loopCount; i++)
_result++;
return _result;
}
}
}
```

Greetings

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.