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 new template for "dotnet new benchmark" #1028

Closed
adamsitnik opened this issue Jan 28, 2019 · 19 comments · Fixed by #1044
Closed

Add new template for "dotnet new benchmark" #1028

adamsitnik opened this issue Jan 28, 2019 · 19 comments · Fixed by #1044
Assignees
Milestone

Comments

@adamsitnik
Copy link
Member

I think that we should add a new template for dotnet cli that would create following app when used:

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace BenchmarkApp
{
    class Program
    {
        static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
    }

    public class TypeWithBenchmarks
    {
        [Benchmark]
        public int YourBenchmark()
        {
            // implement your benchmark here
            return 0;
        }
    }
}

@AndreyAkinshin what do you think?

@AndreyAkinshin
Copy link
Member

@adamsitnik I like this idea!

@adamsitnik
Copy link
Member Author

btw the .csproj should be:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>$whatUserHasAskedFor</TargetFramework>
    <OutputType>Exe</OutputType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <Optimize>true</Optimize>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.1*" />
    <PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.1*" />
  </ItemGroup>

</Project>

@CodeTherapist
Copy link
Contributor

I would like to do this :)

@adamsitnik
Copy link
Member Author

@CodeTherapist awesome! please let me know if you need anything

@dzmitry-lahoda
Copy link

Would it be possible to have template for F# and with more code (i.e. template with examples) like next TheAngryByrd/BenchmarkDotNet.Template#3 ?

@TheAngryByrd
Copy link

I'd be happy to just port the code I have in that repo to something under here as it will get more love and attention.

@JamieKeeling
Copy link

JamieKeeling commented May 3, 2019

I've written a template or two before and would love to help.

Before I get started could you provide some basic information?

  1. Where would you prefer the template content to be stored within the repository? Alternatively would a separate repository be better and ownership transferred.
  2. Templating supports file system or Nuget installation. File system is a low bar of entry but Nuget is ultimately more flexible and easier for consumers albeit requires CI/CD to build the package. What's your preference?

@Kavignon
Copy link

How can I be of help here?

@AndreyAkinshin
Copy link
Member

@Kavignon we already have a pull request by @CodeTherapist with basic template support: #1044 However, I raised some concerns about the current PR status: #1044 (review) . I think it will be better to continue discussion there and finish the PR.
@CodeTherapist do you need any help with the PR?

@CodeTherapist
Copy link
Contributor

@AndreyAkinshin No help needed, thanks - I will finish it this week(end).

@AndreyAkinshin
Copy link
Member

@CodeTherapist awesome, thanks!

CodeTherapist added a commit to CodeTherapist/BenchmarkDotNet that referenced this issue Sep 6, 2019
# Conflicts:
#	docs/articles/guides/toc.yml
@AndreyAkinshin AndreyAkinshin added this to the v0.11.6 milestone Sep 9, 2019
@am11
Copy link
Member

am11 commented Oct 11, 2019

@AndreyAkinshin, when would the official template package made available on nuget.org?

e.g.

and unofficial packages of BenchmarkDotNet:

@AndreyAkinshin
Copy link
Member

@am11 official template was published a few days ago: https://www.nuget.org/packages/BenchmarkDotNet.Templates/

@TheAngryByrd
Copy link

I just marked my github repo as archived and my nuget package as deprecated.

@AndreyAkinshin
Copy link
Member

@TheAngryByrd great, thanks!

@am11
Copy link
Member

am11 commented Oct 28, 2019

Thank you @AndreyAkinshin! 🎉

[maybe not a huge deal but..]
IMHO, the template should be in a runnable state with these additions:

Click to expand
--- a/Benchmarks.cs
+++ b/Benchmarks.cs
using System;
using BenchmarkDotNet;
using BenchmarkDotNet.Attributes;
+using BenchmarkDotNet.Running;
 
 namespace Sample
 {
+    class Program
+    {
+        static void Main() => BenchmarkRunner.Run<Benchmarks>();
+    }
+
     public class Benchmarks
     {
         [Benchmark]

--- a/Sample.csproj
+++ b/Sample.csproj
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFrameworks>netstandard2.0</TargetFrameworks>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+    <OutputType>Exe</OutputType>
   </PropertyGroup>
   <PropertyGroup>
     <PlatformTarget>AnyCPU</PlatformTarget>

So the getting started steps would look like:

dotnet new benchmark --name Sample
cd Sample
dotnet run

@TheAngryByrd
Copy link

there's a CLI flag for that with the template --console-app

dotnet new benchmark --console-app

I know I missed it the first time. I could argue for it being the default too :)

@CodeTherapist
Copy link
Contributor

CodeTherapist commented Oct 28, 2019

Thanks @am11 and @TheAngryByrd for your feedback and question. I'm happy to help.
The template has this "runnale state" as an option when you create the new project (docs):

dotnet new benchmark --name Sample --console-app
cd Sample
dotnet run

Alternatively, you could install and use the the global BenchmarkDotNet tool and invoke the benchmarks from the CLI (docs).

BenchmarkDotnet will strengthen it's integration with leading IDE's in the future to provide better user experience and workflow - similiar to unit tests.
Neverless, any feedback is appreciated and will be considered for further releases.

@am11
Copy link
Member

am11 commented Oct 28, 2019

Great! Thanks for your help and documentation. 👍

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 a pull request may close this issue.

8 participants