BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Passing BenchmarkNumber to BenchmarkSwitcher not working in V0.11.0

Open Tornhoof opened this issue 8 years ago • 8 comments

In V0.11.0, I can't directly pass the benchmark number anymore to the application in .NET Core 2.1.1. Previously it worked like: dotnet run -c Release -- 1

Expected Result:

  • I can pass the number to it and it exexutes it

Actual Result:

  • It hangs after:
Available Benchmarks:
  #0 Benchmark1
  #1 Benchmark2


You should select the target benchmark(s). Please, print a number of a benchmark (e.g. '0') or a contained benchmark caption (e.g. 'Benchmark1'):
If you want to select few, please separate them with space ` ` (e.g. `1 2 3`)
You can also provide the class name in console arguments by using --filter. (e.g. '--filter *Benchmark1*'):

Note: Neither the number nor '*' work, --filter *B1 works.

Repro below:

  1. Build Repro
  2. Run dotnet run -c Release -- 1
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace BenchmarkSwitcherBug
{
    class Program
    {
        static void Main(string[] args)
        {
            var switcher = new BenchmarkSwitcher(typeof(Program).Assembly);
            switcher.Run(args);
        }
    }

    public class Benchmark1
    {
        [Benchmark]
        public void B1()
        {

        }
    }

    public class Benchmark2
    {
        [Benchmark]
        public void B1()
        {

        }
    }
}

Tornhoof avatar Jul 23 '18 19:07 Tornhoof

I looked a bit through the Command Line parsing code and I don't think that functionality is easy to add back (except for *, which directly maps to "-f *"), writing the error message with the existing benchmarks happens after the actual config parsing, so short of either rewriting that part of adding a custom UserInputBenchmarkFilter (which would be useless outside exactly this scenario and doesn't fit in IFilter) I don't see many clean options.

Tornhoof avatar Jul 24 '18 07:07 Tornhoof

I've the same case for .NET 4.6.

When you pass the parameter with "--filter benchmarkname" the parameter "--filter" is not being recognized and it throws the --help to see all parameters. And when I use "-f benchmarkname", fullnamespaces or wildcards it doesn't works too, it shows the ones that are detected as examples but not for running. The message is "The filter that you have provided returned 0 benchmarks."

Regards.

Ryujose avatar Jul 24 '18 17:07 Ryujose

The best person who can handle these question is @adamsitnik, he will be available the next week.

AndreyAkinshin avatar Jul 25 '18 09:07 AndreyAkinshin

@Tornhoof I've taken a look on the tests of the library, and performed the tests on the implementation and you've to insert the --filter without the ", because if you place the " it goes in one parameter and when you insert without it, it goes with two and it's prepared only for two parameters instead of whole one. You can take a look at the test "WhenJobIsDefinedInTheConfigAndArgumentsDontContainJobArgumentOnlySingleJobIsUsed" on "BenchmarkSwitcherTest" if you're curious about it :)

Ryujose avatar Jul 26 '18 00:07 Ryujose

@Tornhoof I don't know if you've the same problem that I had. But I've done the same with the numbers and have the same behaviour. I don't know if your issue comes from the same place because your trying to do it with the compile parameters of dotnet core and right now I don't have an implementation to test with it, I suppose it use the same input.

Ryujose avatar Jul 26 '18 01:07 Ryujose

@Ryujose Mine is specifically only about passing those numbers into the benchmark, there is simply said no code to accept parameters without a name (e.g. -f) anymore.

Tornhoof avatar Jul 26 '18 06:07 Tornhoof

@Tornhoof The problem is on the filter of benchmarks in the class "BenchmarkConverter.cs" on line 74. If you go inside of the method to the predicate on class "GlobFilter.cs", line 24, there's a filter and it doesn't comes with any value, if you go with -f 0 for example.

If I've sometime available I'll take a best look about it.

Ryujose avatar Jul 26 '18 12:07 Ryujose

Hi @Tornhoof @Ryujose

This is a breaking change that was introduced on purpose.

The numbers can change over the time as you add new benchmarks to your assembly. You can now use the new powerful glob filtering

I believe that once you get used to it you won't be willing to "go back"

adamsitnik avatar Jul 31 '18 15:07 adamsitnik