Skip to content

Commit

Permalink
align iteration mode
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed May 23, 2018
1 parent e34fc7a commit 8ae23e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/BenchmarkDotNet/Reports/Measurement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Extensions;
Expand All @@ -13,6 +14,8 @@ public struct Measurement : IComparable<Measurement>
{
private static readonly Measurement Error = new Measurement(-1, IterationMode.Unknown, 0, 0, 0);

private static readonly int IterationModeNameMaxWidth = Enum.GetNames(typeof(IterationMode)).Max(text => text.Length);

public IterationMode IterationMode { get; }

public int LaunchIndex { get; }
Expand Down Expand Up @@ -48,10 +51,13 @@ public Measurement(int launchIndex, IterationMode iterationMode, int iterationIn

public string ToOutputLine()
{
string alignedIterationMode = IterationMode.ToString().PadRight(IterationModeNameMaxWidth, ' ');

// Usually, a benchmarks takes more than 10 iterations (rarely more than 99)
// PadLeft(2, ' ') looks like a good trade-off between alignment and amount of characters
string alignedIterationIndex = IterationIndex.ToString().PadLeft(2, ' ');
return $"{IterationMode} {alignedIterationIndex}: {GetDisplayValue()}";

return $"{alignedIterationMode} {alignedIterationIndex}: {GetDisplayValue()}";
}

private string GetDisplayValue() => $"{Operations} op, {Nanoseconds.ToStr("0.00")} ns, {GetAverageTime()}";
Expand Down
2 changes: 1 addition & 1 deletion tests/BenchmarkDotNet.Tests/Engine/EngineFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void ForJobsWithExplicitUnrollFactorTheGlobalSetupIsCalledAndMultiActionC
public void ForJobsThatDontRequirePilotTheGlobalSetupIsCalledAndMultiActionCodeGetsJitted()
=> AssertGlobalSetupWasCalledAndMultiActionGotJitted(Job.Default.WithInvocationCount(100));

public void AssertGlobalSetupWasCalledAndMultiActionGotJitted(Job job)
private void AssertGlobalSetupWasCalledAndMultiActionGotJitted(Job job)
{
var engineParameters = CreateEngineParameters(mainSingleAction: Throwing, mainMultiAction: Instant16, job: job);

Expand Down

0 comments on commit 8ae23e8

Please sign in to comment.