Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Added sample project for BenchmarkDotNet #6

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CloudMessagesApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Messages.Helpers", "Messages.Helpers\Messages.Helpers.csproj", "{8535430B-92DB-4C95-9D2C-1DB6CF5F3956}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messages.Benchmark", "Messages.Benchmark\Messages.Benchmark.csproj", "{AD00B0E3-C0D6-4CC5-80A3-D013AC3E1F1F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,6 +33,14 @@ Global
{0BF48F7E-D68E-41B1-B1E8-73C0FFF2C192}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BF48F7E-D68E-41B1-B1E8-73C0FFF2C192}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BF48F7E-D68E-41B1-B1E8-73C0FFF2C192}.Release|Any CPU.Build.0 = Release|Any CPU
{8535430B-92DB-4C95-9D2C-1DB6CF5F3956}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8535430B-92DB-4C95-9D2C-1DB6CF5F3956}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8535430B-92DB-4C95-9D2C-1DB6CF5F3956}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8535430B-92DB-4C95-9D2C-1DB6CF5F3956}.Release|Any CPU.Build.0 = Release|Any CPU
{AD00B0E3-C0D6-4CC5-80A3-D013AC3E1F1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD00B0E3-C0D6-4CC5-80A3-D013AC3E1F1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD00B0E3-C0D6-4CC5-80A3-D013AC3E1F1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD00B0E3-C0D6-4CC5-80A3-D013AC3E1F1F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions Messages.Api/Controllers/MessagesController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Messages.Api.Helpers;
using Messages.Api.Models;
using Messages.Api.Models;
using Messages.Api.Services;
using Messages.Helpers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
Expand Down
4 changes: 4 additions & 0 deletions Messages.Api/Messages.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Messages.Helpers\Messages.Helpers.csproj" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions Messages.Benchmark/Messages.Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Messages.Helpers\Messages.Helpers.csproj" />
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions Messages.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Messages.Helpers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace Messages.Benchmark
{
#pragma warning disable CA1822 // Mark members as static
[MinColumn, MaxColumn]
[MarkdownExporter, AsciiDocExporter, HtmlExporter, CsvExporter]
public class MyBenchmark
{
[Benchmark]
public void ShortPalindromeWord() => "racecar".IsPalindrome();

[Benchmark]
public void ShortPalindromeName() => "Anna".IsPalindrome();

[Benchmark]
public void SingleCharacter() => "x".IsPalindrome();

[Benchmark]
public void SequenceOfRepeatedNumbers() => "9999999999999999999".IsPalindrome();

[Benchmark]
public void SequenceOfRandomNumbers() => "865357943037344".IsPalindrome();

[Benchmark]
public void EnglishPalindromeMessage() => "Cigar? Toss it in a can. It is so tragic.".IsPalindrome();

[Benchmark]
public void NonEnglishPalindromeMessage() => "Socorram-me, subi no ônibus em Marrocos".IsPalindrome();

[Benchmark]
public void NonPalindromeMessage() => "this is not a palindrome".IsPalindrome();
}
#pragma warning restore CA1822 // Mark members as static

class Program
{
static void Main()
{
BenchmarkRunner.Run<MyBenchmark>();
}
}
}
5 changes: 5 additions & 0 deletions Messages.Helpers/Messages.Helpers.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Globalization;
using System.Text;

namespace Messages.Api.Helpers
namespace Messages.Helpers
{
public static class StringExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion Messages.Tests/Helpers/PalindromeTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Messages.Api.Helpers;
using Messages.Helpers;
using System;
using Xunit;

Expand Down