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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>BenchmarkDotNet.BenchmarkProjectTemplate.CSharp</id>
<version>0.11.3</version>
<description>A Benchmark project template.</description>
<authors>BenchmarkDotNet</authors>
<copyright>.NET Foundation and contributors</copyright>
<tags>benchmark;benchmarking;performance;template</tags>
<iconUrl>https://raw.githubusercontent.com/dotnet/BenchmarkDotNet/master/docs/guide/logo.png</iconUrl>
<projectUrl>https://github.com/dotnet/BenchmarkDotNet</projectUrl>
CodeTherapist marked this conversation as resolved.
Show resolved Hide resolved
<license>MIT</license>
<RepositoryType>git</RepositoryType>
<repository>https://github.com/dotnet/BenchmarkDotNet</repository>
<packageTypes>
<packageType name="Template" />
</packageTypes>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"$schema": "http://json.schemastore.org/template",
"identity": "BenchmarkDotNet.BenchmarkProjectTemplate.CSharp",
"name": "Benchmark Project",
"shortName": "benchmark",
"groupIdentity": "BenchmarkDotNet",
"classifications": [
"Benchmark",
"Library"
],
"precedence": "3000",
"tags": {
"language": "C#",
"type": "project"
},
"description": "A project template for creating benchmarks.",
"author": "BenchmarkDotnet",
"generatorVersions": "[1.0.0.0-*)",

"sourceName": "_BenchmarkProjectName_",
"preferNameDirectory": true,
"defaultName": "MyBenchmark",
"symbols": {
"benchmarkName": {
"type": "parameter",
"datatype": "string",
"description": "The name of the benchmark class.",
"defaultValue": "MyBenchmark",
"FileRename" : "_BenchmarkName_",
"replaces": "$(BenchmarkName)"
},
"frameworks": {
"type": "parameter",
"datatype": "string",
"description": "The target framework(s) for the project (e.g. netstandard2.0;net472).",
"defaultValue": "netstandard2.0",
CodeTherapist marked this conversation as resolved.
Show resolved Hide resolved
"replaces": "$(Frameworks)"
},
"config": {
"type": "parameter",
"datatype": "bool",
"description": "Adds a benchmark config class.",
"defaultValue": "false"
},
"skipRestore": {
"type": "parameter",
"datatype": "bool",
"description": "If specified, skips the automatic restore of the project on create.",
"defaultValue": "false"
}
},
"sources": [
{
"source": "./",
"target": "./",
"exclude": [
".template.config/**"
],
"modifiers": [
{
"condition": "(!config)",
"exclude": [
"BenchmarkConfig.cs"
]}
]
}
],
"primaryOutputs": [
{
"path": "_BenchmarkProjectName_.csproj"
}
],
"postActions": [
{
"condition": "(!skipRestore)",
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [
{
"text": "Run 'dotnet restore'"
}
],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;


CodeTherapist marked this conversation as resolved.
Show resolved Hide resolved
namespace _BenchmarkProjectName_
{

CodeTherapist marked this conversation as resolved.
Show resolved Hide resolved
public class BenchmarkConfig : ManualConfig
{
public Config()
{
// Configure your benchmarks, see for more details: https://benchmarkdotnet.org/articles/configs/configs.html.
//Add(Job.Dry);
//Add(ConsoleLogger.Default);
//Add(TargetMethodColumn.Method, StatisticColumn.Max);
//Add(RPlotExporter.Default, CsvExporter.Default);
//Add(EnvironmentAnalyser.Default);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using BenchmarkDotNet;
using BenchmarkDotNet.Attributes;

namespace _BenchmarkProjectName_
{
#if(config)
[Config(typeof(BenchmarkConfig))]
#endif
public class $(BenchmarkName)
{

[Benchmark]
public void YourBenchmark()
{
// Implement your benchmark here


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(Frameworks)</TargetFrameworks>
<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>