Skip to content

Commit 8ed521f

Browse files
authored
Added a command line arg for not inducing any GCs while running Benchmarks (#2101)
1 parent 3a18b18 commit 8ed521f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public bool UseDisassemblyDiagnoser
209209
[Option("wasmDataDir", Required = false, HelpText = "Wasm data directory")]
210210
public DirectoryInfo WasmDataDirectory { get; set; }
211211

212+
[Option("noForcedGCs", Required = false, HelpText = "Specifying would not forcefully induce any GCs.")]
213+
public bool NoForcedGCs { get; set; }
214+
212215
internal bool UserProvidedFilters => Filters.Any() || AttributeNames.Any() || AllCategories.Any() || AnyCategories.Any();
213216

214217
[Usage(ApplicationAlias = "")]

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ private static Job GetBaseJob(CommandLineOptions options, IConfig globalConfig)
294294
baseJob = baseJob.RunOncePerIteration();
295295
if (options.MemoryRandomization)
296296
baseJob = baseJob.WithMemoryRandomization();
297+
if (options.NoForcedGCs)
298+
baseJob = baseJob.WithGcForce(false);
297299

298300
if (options.EnvironmentVariables.Any())
299301
{

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,5 +560,17 @@ public void InvalidEnvVarAreRecognized()
560560
{
561561
Assert.False(ConfigParser.Parse(new[] { "--envVars", "INVALID_NO_SEPARATOR" }, new OutputLogger(Output)).isSuccess);
562562
}
563+
564+
[Fact]
565+
public void UserCanSpecifyNoForceGCs()
566+
{
567+
var parsedConfiguration = ConfigParser.Parse(new[] { "--noForcedGCs" }, new OutputLogger(Output));
568+
Assert.True(parsedConfiguration.isSuccess);
569+
570+
foreach (var job in parsedConfiguration.config.GetJobs())
571+
{
572+
Assert.False(job.Environment.Gc.Force);
573+
}
574+
}
563575
}
564576
}

0 commit comments

Comments
 (0)