-
-
Notifications
You must be signed in to change notification settings - Fork 962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ParamsSource #350
Comments
I like the approach! |
Same here, this looks like a nice extension to the existing way of doing
The only other one I can think of is |
Something to consider here is cases where the In my case we have a little tool that validates that code snippets follow a set of rules we have for our code base. Each validation has it's own class implementing our // This list is much longer in reality and we expect to have hundreds of rules over time
[Params(
typeof(SomeRule),
typeof(AnotherRule),
typeof(ThirdRule))]
public Type ruleType;
public IRule rule;
[GlobalSetup]
public void Setup()
{
// container setup and other stuff up here
// ...
rule = container.Resolve(ruleType) as IRule;
}
[Benchmark]
public int Validate()
{
return rule.Validate();
} This way is no fun to maintain since we need to explicitly add every new rule added to the benchmark. It would be nice if it could be something like this instead: [ParamsSource("GetRules")]
public IRule rule;
public IEnumerable<IRule> GetRules()
{
foreach(var rule in container.ResolveMany<IRule>())
{
yield return rule;
}
}
[GlobalSetup]
public void Setup()
{
// container setup and other stuff up here as usual
// ...
}
[Benchmark]
public int Validate()
{
return rule.Validate();
} Then we wouldn't need to manually maintain the attribute and can get rid of the ugly unit test. I hope that makes sense. Also is this one something that could be up for grabs by others? I could be tempted to spend my 20% time at work for a while on this if that were the case. |
@HenrikPoulsen sure! Please let me know if you need any help! |
@adamsitnik Cool. I will look at it then. |
I had some spare time today and decided to implement it ;) Docs public class IntroParamsSource
{
[ParamsSource(nameof(ValuesForA))]
public int A { get; set; } // property with public setter
[ParamsSource(nameof(ValuesForB))]
public int B; // public field
public IEnumerable<int> ValuesForA => new[] { 100, 200 }; // public property
public static IEnumerable<int> ValuesForB() => new[] { 10, 20 }; // public static method
[Benchmark]
public void Benchmark() => Thread.Sleep(A + B + 5);
} @HenrikPoulsen I have reused the code we had for Params. So it works in the same way (order of method execution) The problem we have is that the values have to be "serializable" because we generate and build a new project for every benchmark. So this is why you still have to return an collection of I don't like this limitation, but currently I don't have any good idea how to solve it (at some point of time we generate C# file with |
@HenrikPoulsen I created new thing, called |
@adamsitnik I played around with IParam today and it covers all my needs. Thanks! |
@HenrikPoulsen great, thanks for the feedback! |
I suggest to add an ability to generate source for
Params
via additional methods. An example:The
ParamsSource
approach should also resolves #37, #256, #317.@mattwarren, @adamsitnik, what do you think? Is the
ParamsSource
name is good enough for this attribute or we should choose another name?The text was updated successfully, but these errors were encountered: