Skip to content

Commit 765d529

Browse files
authored
allow the users to specify Platform via console args (#1492)
1 parent 254da42 commit 765d529

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/BenchmarkDotNet/ConsoleArguments/CommandLineOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using BenchmarkDotNet.ConsoleArguments.ListBenchmarks;
66
using BenchmarkDotNet.Diagnosers;
77
using BenchmarkDotNet.Engines;
8+
using BenchmarkDotNet.Environments;
89
using BenchmarkDotNet.Helpers;
910
using CommandLine;
1011
using CommandLine.Text;
@@ -131,6 +132,9 @@ public class CommandLineOptions
131132
[Option("strategy", Required = false, HelpText = "The RunStrategy that should be used. Throughput/ColdStart/Monitoring.")]
132133
public RunStrategy? RunStrategy { get; set; }
133134

135+
[Option("platform", Required = false, HelpText = "The Platform that should be used. If not specified, the host process platform is used (default). AnyCpu/X86/X64/Arm/Arm64.")]
136+
public Platform? Platform { get; set; }
137+
134138
[Option("runOncePerIteration", Required = false, Default = false, HelpText = "Run the benchmark exactly once per iteration.")]
135139
public bool RunOncePerIteration { get; set; }
136140

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ private static Job GetBaseJob(CommandLineOptions options, IConfig globalConfig)
264264
baseJob = baseJob.WithUnrollFactor(options.UnrollFactor.Value);
265265
if (options.RunStrategy.HasValue)
266266
baseJob = baseJob.WithStrategy(options.RunStrategy.Value);
267+
if (options.Platform.HasValue)
268+
baseJob = baseJob.WithPlatform(options.Platform.Value);
267269
if (options.RunOncePerIteration)
268270
baseJob = baseJob.RunOncePerIteration();
269271

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,22 @@ public void UserCanSpecifyEnvironmentVariables()
434434
Assert.Equal(value, envVar.Value);
435435
}
436436

437+
[Theory]
438+
[InlineData(Platform.AnyCpu)]
439+
[InlineData(Platform.X86)]
440+
[InlineData(Platform.X64)]
441+
[InlineData(Platform.Arm)]
442+
[InlineData(Platform.Arm64)]
443+
public void UserCanSpecifyProcessPlatform(Platform platform)
444+
{
445+
var parsedConfig = ConfigParser.Parse(new[] { "--platform", platform.ToString() }, new OutputLogger(Output)).config;
446+
447+
var job = parsedConfig.GetJobs().Single();
448+
var parsed = job.Environment.Platform;
449+
450+
Assert.Equal(platform, parsed);
451+
}
452+
437453
[Fact]
438454
public void InvalidEnvVarAreRecognized()
439455
{

0 commit comments

Comments
 (0)