Skip to content
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

Add "dotnet new" benchmark project template #1044

Merged
merged 11 commits into from
Sep 9, 2019

Conversation

CodeTherapist
Copy link
Contributor

@CodeTherapist CodeTherapist commented Feb 3, 2019

The template supports the following parameters:

benchmarktemplate

Usage example:

dotnet new benchmark -n=MyCompany.Namespace.Benchmarks -b=MyBechmark -f="netstandard2.0;net472"

The template is a library, not as proposed a exe - I suggest that users should take advantage of the dotnet global tool to run the benchmarks, instead of creating a console app.
The config parameter will conditionally add a benchmark config class and reference it inside the the benchmark class.

  • Initial release
  • Documentation

The documentation will be delivered as soon the template is approved.

Closes #1028

@CatGirlsAreLife
Copy link

Nice, can I test this template locally on Windows 10 build 18317 x64?

@CodeTherapist
Copy link
Contributor Author

@CatGirlsAreLife Yes, you could test this on windows. To do so install the template from the directory location like this:

dotnet new -i [path-to-the-nuspec-directory-of-the-template]

After that, you can use it as I described already.

@Therzok
Copy link

Therzok commented Jun 2, 2019

@adamsitnik @AndreyAkinshin is there interest in publishing this?

@CodeTherapist mind if I add some commits on top of yours in another PR?

Fix typos.
Align accordingly to PR feedback
@CodeTherapist
Copy link
Contributor Author

CodeTherapist commented Jul 7, 2019

@Therzok Thanks for helping me out, very appreciated.
@dzmitry-lahoda and @TheAngryByrd Thanks for the F# template, used it as base line - included it in my last commit. How you like it?

Added a VB.NET and a F# template as well. Even I'm primarily using C# to get cool things done - I decided to provide them with the exact same capability and behavior as the C# template.

After installation:

BDN-Templates

Building them as is:

BDN-Build

Create the template nuget packages (using nuget 5.x)

nuget pack BenchmarkDotNet.BenchmarkProjectTemplate.CSharp.nuspec
nuget pack BenchmarkDotNet.BenchmarkProjectTemplate.VB.nuspec
nuget pack BenchmarkDotNet.BenchmarkProjectTemplate.FSharp.nuspec

Installing the template nuget packages

dotnet new -i BenchmarkDotNet.BenchmarkProjectTemplate.CSharp
dotnet new -i BenchmarkDotNet.BenchmarkProjectTemplate.VB
dotnet new -i BenchmarkDotNet.BenchmarkProjectTemplate.FSharp

Using the template

dotnet new benchmark -n=MyCompany.Namespace.CSharp.Benchmarks -b=MyBechmark -c=true -f="netstandard2.0;net472" -lang C#

Accordingly, you can use -lang F# or -lang VB.

@TheAngryByrd
Copy link

I had some issues with the F# template. I sent a PR to your branch to fix them CodeTherapist#1

@AndreyAkinshin AndreyAkinshin self-requested a review July 13, 2019 11:59
Copy link
Member

@AndreyAkinshin AndreyAkinshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeTherapist thanks for the pull request and sorry for such a late reply. I was pretty busy during the last several months and didn't have enough time for BenchmarkDotNet.

In general, it looks and works great! It would be awesome to have such templates in the terminal. However, I have several concerns:

  1. Currently, we have three different NuGet packages with templates which should be installed independently. It will be better to have only one NuGet package to them all. You can use the NUnit 3 Test Project Template as an example.
  2. It's better to use the current version of BenchmarkDotNet in the csproj file instead of 0.1*. We didn't release the 1.0 version, which allows us to make some breaking changes from time to time (of course, we prefer to make backward compatible releases when it's possible). So, I don't really like the floating NuGet package reference versions because a new release of BenchmarkDotNet can spoil the existing solutions.
  3. Other templates (like console, classlib, xunit, mvc) use the --no-restore option for skipping restore. It would be nice to use the same name to be consistent.
  4. It will be better to reference BenchmarkDotNet.Diagnostics.Windows only if a benchmark is created on Windows.
  5. I prefer to use the current BenchmarkDotNet version as a template version (in the nuspec file). It will simplify syncing between templates and new versions of the library.
  6. Since we don't have proper support of BenchmarkDotNet projects in IDEs (VS, Rider) as we have for unit tests, it will be better to create a netcoreapp project by default with the following Main method:
class Program
{
    static void Main(string[] args)
    {
        BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
    }
}

It will help developers to easily run benchmarks from an IDE during the benchmark design stage.

@CodeTherapist
Copy link
Contributor Author

thanks for the pull request and sorry for such a late reply. I was pretty busy during the last several months and didn't have enough time for BenchmarkDotNet.

No issue, we are all usually busy 👍 Thanks for your answers and your time, reviewing my PR.

I agree on all your statements except for number six: I think we should encourage the users to use the awesome dotnet tool (#213) to run the benchmarks quickly - I will add it as optional option.
Beside that I think a first-class integration into the most used IDE's (VS, Rider and VS Code) would make sense and would increase acceptance to use benchmark dotnet.

@AndreyAkinshin
Copy link
Member

I agree on all your statements except for number six: I think we should encourage the users to use the awesome dotnet tool

@adamsitnik what do you think?

Beside that I think a first-class integration into the most used IDE's (VS, Rider and VS Code) would make sense and would increase acceptance to use benchmark dotnet.

Yeah, it will be great. I already working on the advanced BenchmarkDotNet support in Rider.

* One nuget package for all templates
* No floating version for nuget references
* --no-restore instead of skipRestore
* `BenchmarkDotNet.Diagnostics.Windows` only on Windows
* Sync template version with BenchmarkDotNet version
@CodeTherapist
Copy link
Contributor Author

CodeTherapist commented Sep 2, 2019

  • 1. Currently, we have three different NuGet packages with templates which should be installed independently. It will be better to have only one NuGet package to them all.

  • 2. It's better to use the current version of BenchmarkDotNet in the csproj file instead of 0.1*.

  • 3. Other templates (like console, classlib, xunit, mvc) use the --no-restore option for skipping restore. It would be nice to use the same name to be consistent.

  • 4. It will be better to reference BenchmarkDotNet.Diagnostics.Windows only if a benchmark is created on Windows.

  • 5. I prefer to use the current BenchmarkDotNet version as a template version (in the nuspec file). It will simplify syncing between templates and new versions of the library.

  • 6. Since we don't have proper support of BenchmarkDotNet projects in IDEs (VS, Rider) as we have for unit tests, it will be better to create a netcoreapp project by default with the following Main method [...]

@AndreyAkinshin Thanks for your review - everything done, except number 6.
Added a basic documentation for the templates as well.

@AndreyAkinshin
Copy link
Member

except number 6

What do you think about "netcoreapp with Main method" as an option? (We can keep the existing behaviour with netstandard/classlib as the default)

@CodeTherapist
Copy link
Contributor Author

CodeTherapist commented Sep 6, 2019

except number 6

What do you think about "netcoreapp with Main method" as an option? (We can keep the existing behaviour with netstandard/classlib as the default)

Sure! Also thought about that and mentioned this few comments earlier as well.
How about --consoleapp as options name?

@AndreyAkinshin
Copy link
Member

How about --consoleapp as options name?

LGTM.

Could you please also merge master into your branch and resolve the conflicts?

# Conflicts:
#	docs/articles/guides/toc.yml
@AndreyAkinshin
Copy link
Member

@CodeTherapist in general, it works great! I will merge the PR as soon as you introduce the --consoleapp option.

* --console-app is an optional template parameter to create a console app project.
* Minor fixes and better default names.
* Updating docs
@CodeTherapist
Copy link
Contributor Author

@AndreyAkinshin: The --console-app is implemented, docs are updated and conflicts are resolved.

The templates are not tested at the moment during the build. I think we should do this to ensure further changes do not break the templates. What do you think?

@AndreyAkinshin AndreyAkinshin merged commit 76096e2 into dotnet:master Sep 9, 2019
@AndreyAkinshin AndreyAkinshin added this to the v0.11.6 milestone Sep 9, 2019
@AndreyAkinshin
Copy link
Member

@CodeTherapist everything works great! Thank you very much for your contribution!

@ulex
Copy link

ulex commented Sep 4, 2021

@CodeTherapist first of all, thanks for the template, very appreciated!
let me share the experience of using it. I've found this this issue when I was wondering why the default isn't a console application. The first place where I found the llink to the global tool was the current issue. It is nice, that there is a console tool for running benchmark, but there is no way to figure about it from documentation. I checked these places:

  1. Getting Started shows example with command-line application
  2. How to run your benchmarks explictly states, that

    There are several ways to run your benchmarks. What is important is that BenchmarkDotNet works only with Console Apps.

  3. Even the page about templates didn't mention global tool at all

IMO it seems like either more promotion of global tools is required, or default value should be changed.

@GF-Huang
Copy link

GF-Huang commented Nov 30, 2021

After install the template, I create a BenchmarkDotNet project in VS2022, it creates a solution with an empty project folder, without any project files.

references:

@GF-Huang
Copy link

I try to create project by command line dotnet new benchmark, it creates a library project, it's crazy to the docs!!!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new template for "dotnet new benchmark"
8 participants