-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Enables benchmarking betweeen different Nuget packages #922
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fbc1d08
Initial commit with sample test for Nuget with newtonsoft
Shazwazza 3de64ce
missing brace (oops!)
Shazwazza bc04fae
adds notes
Shazwazza 8233eb8
Merge remote-tracking branch 'source/master' into 290-nuget-support
Shazwazza f54d2bd
Updated code for nuget support merged with latest code in project
Shazwazza eafad74
reverts uneeded change to DotNetCliBuilder
Shazwazza 8067f37
reverts uneeded change to DotNetCliBuilder
Shazwazza d337a04
reverts uneeded change to DotNetCliGenerator
Shazwazza feb4dd0
Fixes test
Shazwazza 8936840
Updates IntroNuget, adds comments, adds ref to newtonsoft
Shazwazza 1e78458
Adds integration and unit test, ensures that multiple packages can be…
Shazwazza 7343f2c
Adds check to RoslynToolchain for nuget dependencies, adds unit tests…
Shazwazza 4ce6b5f
Removes the OfType since it's not required
Shazwazza 0d6c464
removes TODO note
Shazwazza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Threading; | ||
| using BenchmarkDotNet.Analysers; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Columns; | ||
| using BenchmarkDotNet.Configs; | ||
| using BenchmarkDotNet.Engines; | ||
| using BenchmarkDotNet.Exporters.Csv; | ||
| using BenchmarkDotNet.Jobs; | ||
| using BenchmarkDotNet.Loggers; | ||
| using BenchmarkDotNet.Toolchains.CsProj; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace BenchmarkDotNet.Samples | ||
| { | ||
| /// <summary> | ||
| /// Benchmarks between various versions of a Nuget package | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Only supported with the DotNetCliBuilder toolchain | ||
| /// </remarks> | ||
| [Config(typeof(Config))] | ||
| public class IntroNuget | ||
| { | ||
| private class Config : ManualConfig | ||
| { | ||
| public Config() | ||
| { | ||
| //Specify jobs with different versions of the same Nuget package to benchmark. | ||
| //The Nuget versions referenced on these jobs must be greater or equal to the | ||
| //same Nuget version referenced in this benchmark project. | ||
| //Example: This benchmark project references Newtonsoft.Json 9.0.1 | ||
| Add(Job.MediumRun.With(CsProjCoreToolchain.Current.Value).WithNuget("Newtonsoft.Json", "11.0.2").WithId("11.0.2")); | ||
| Add(Job.MediumRun.With(CsProjCoreToolchain.Current.Value).WithNuget("Newtonsoft.Json", "11.0.1").WithId("11.0.1")); | ||
| Add(Job.MediumRun.With(CsProjCoreToolchain.Current.Value).WithNuget("Newtonsoft.Json", "10.0.3").WithId("10.0.3")); | ||
| Add(Job.MediumRun.With(CsProjCoreToolchain.Current.Value).WithNuget("Newtonsoft.Json", "10.0.2").WithId("10.0.2")); | ||
| Add(Job.MediumRun.With(CsProjCoreToolchain.Current.Value).WithNuget("Newtonsoft.Json", "10.0.1").WithId("10.0.1")); | ||
| Add(Job.MediumRun.With(CsProjCoreToolchain.Current.Value).WithNuget("Newtonsoft.Json", "9.0.1").WithId("9.0.1")); | ||
| Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); | ||
| Add(DefaultConfig.Instance.GetLoggers().ToArray()); | ||
| Add(CsvExporter.Default); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void SerializeAnonymousObject() => JsonConvert.SerializeObject(new { hello = "world", price = 1.99, now = DateTime.UtcNow }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace BenchmarkDotNet.Jobs | ||
| { | ||
| public class NugetReference : IEquatable<NugetReference> | ||
| { | ||
| public NugetReference(string packageName, string packageVersion) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(packageName)) | ||
| throw new ArgumentException("message", nameof(packageName)); | ||
|
|
||
| PackageName = packageName; | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(PackageVersion) && !IsValidVersion(packageVersion)) | ||
| throw new InvalidOperationException($"Invalid version specified: {packageVersion}"); | ||
|
|
||
| PackageVersion = packageVersion; | ||
|
|
||
| } | ||
|
|
||
| public string PackageName { get; } | ||
| public string PackageVersion { get; } | ||
|
|
||
| public override bool Equals(object obj) | ||
| { | ||
| return Equals(obj as NugetReference); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Object is equals when the package name is the same | ||
| /// </summary> | ||
| /// <param name="other"></param> | ||
| /// <returns></returns> | ||
| /// <remarks> | ||
| /// There can only be one package reference of the same name regardless of version | ||
| /// </remarks> | ||
| public bool Equals(NugetReference other) | ||
| { | ||
| return other != null && | ||
| PackageName == other.PackageName; | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return 557888800 + EqualityComparer<string>.Default.GetHashCode(PackageName); | ||
| } | ||
|
|
||
| public override string ToString() => $"{PackageName}{(string.IsNullOrWhiteSpace(PackageVersion) ? string.Empty : $" {PackageVersion}")}"; | ||
|
|
||
| /// <summary> | ||
| /// Tries to validate the version string | ||
| /// </summary> | ||
| /// <param name="version"></param> | ||
| /// <returns></returns> | ||
| private bool IsValidVersion(string version) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(version)) return false; | ||
| //There is a great nuget package for semver validation called `semver` however we probably | ||
| // don't want to add another dependency here so this will do some rudimentary validation | ||
| // and if that fails, then the actual add package command will fail anyways. | ||
| var parts = version.Split('-'); | ||
| if (parts.Length == 0) return false; | ||
| if (!Version.TryParse(parts[0], out var _)) return false; | ||
| for (int i = 1; i < parts.Length; i++) | ||
| { | ||
| if (!PreReleaseValidator.IsMatch(parts[i])) return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Used to validate all pre-release parts of a semver version | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Allows alphanumeric chars, ".", "+", "-" | ||
| /// </remarks> | ||
| private static readonly Regex PreReleaseValidator = new Regex(@"^[0-9A-Za-z\-\+\.]+$", RegexOptions.Compiled); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.