-
Notifications
You must be signed in to change notification settings - Fork 272
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
TryAddWithoutValidation for multiple values could be more efficient #4240
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Engines; | ||
using MicroBenchmarks; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
|
||
namespace System.Net.Http.Tests | ||
{ | ||
[BenchmarkCategory(Categories.Libraries, Categories.LINQ)] | ||
public class TryAddWithoutValidationTests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a new class for |
||
{ | ||
[Benchmark] | ||
[ArgumentsSource(nameof(IEnumerableArgument))] | ||
public bool AddHeaders(AddWithoutValidationTestData data) => new HttpResponseMessage().Headers.TryAddWithoutValidation("headerName", data.Values); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could make the test more focused on just the adding part, e.g. private readonly HttpResponseHeaders _responseHeaders = new HttpResponseMessage().Headers;
public bool SomeTest()
{
_responseHeaders.Add(...);
_responseHeaders.Clear();
} |
||
|
||
public IEnumerable<AddWithoutValidationTestData> IEnumerableArgument() | ||
{ | ||
yield return new AddWithoutValidationTestData("List", Enumerable.Range(0, 5).Select(i => "value" + i).ToList()); | ||
yield return new AddWithoutValidationTestData("Array", Enumerable.Range(0, 5).Select(i => "value" + i).ToArray()); | ||
yield return new AddWithoutValidationTestData("Hashset", new HashSet<string>(Enumerable.Range(0, 5).Select(i => "value" + i))); | ||
} | ||
} | ||
|
||
public class AddWithoutValidationTestData | ||
{ | ||
public IEnumerable<string> Values { get; } | ||
|
||
public string InstanceName { get; } | ||
|
||
public AddWithoutValidationTestData(string instanceName, IEnumerable<string> values) | ||
{ | ||
InstanceName = instanceName; | ||
Values = values; | ||
} | ||
|
||
public override string ToString() => InstanceName; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.