From 324bc43b7de4161c4e6a9fdd4da6ed2976760ad2 Mon Sep 17 00:00:00 2001
From: Daniel Schmidt Pinheiro <3842788+dscpinheiro@users.noreply.github.com>
Date: Wed, 4 Dec 2019 19:43:27 -0500
Subject: [PATCH] Added sample project for BenchmarkDotNet
---
CloudMessagesApi.sln | 12 +++++
.../Controllers/MessagesController.cs | 4 +-
Messages.Api/Messages.Api.csproj | 4 ++
Messages.Benchmark/Messages.Benchmark.csproj | 12 +++++
Messages.Benchmark/Program.cs | 45 +++++++++++++++++++
Messages.Helpers/Messages.Helpers.csproj | 5 +++
.../StringExtensions.cs | 2 +-
Messages.Tests/Helpers/PalindromeTests.cs | 2 +-
8 files changed, 82 insertions(+), 4 deletions(-)
create mode 100644 Messages.Benchmark/Messages.Benchmark.csproj
create mode 100644 Messages.Benchmark/Program.cs
create mode 100644 Messages.Helpers/Messages.Helpers.csproj
rename {Messages.Api/Helpers => Messages.Helpers}/StringExtensions.cs (98%)
diff --git a/CloudMessagesApi.sln b/CloudMessagesApi.sln
index 4b79999..1dd44fb 100644
--- a/CloudMessagesApi.sln
+++ b/CloudMessagesApi.sln
@@ -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
@@ -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
diff --git a/Messages.Api/Controllers/MessagesController.cs b/Messages.Api/Controllers/MessagesController.cs
index eb7a7bd..968c770 100644
--- a/Messages.Api/Controllers/MessagesController.cs
+++ b/Messages.Api/Controllers/MessagesController.cs
@@ -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;
diff --git a/Messages.Api/Messages.Api.csproj b/Messages.Api/Messages.Api.csproj
index 0f9df2a..1c49954 100644
--- a/Messages.Api/Messages.Api.csproj
+++ b/Messages.Api/Messages.Api.csproj
@@ -22,4 +22,8 @@
+
+
+
+
diff --git a/Messages.Benchmark/Messages.Benchmark.csproj b/Messages.Benchmark/Messages.Benchmark.csproj
new file mode 100644
index 0000000..be0e833
--- /dev/null
+++ b/Messages.Benchmark/Messages.Benchmark.csproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ netcoreapp3.1
+
+
+
+
+
+
+
+
diff --git a/Messages.Benchmark/Program.cs b/Messages.Benchmark/Program.cs
new file mode 100644
index 0000000..f8e6f5c
--- /dev/null
+++ b/Messages.Benchmark/Program.cs
@@ -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();
+ }
+ }
+}
diff --git a/Messages.Helpers/Messages.Helpers.csproj b/Messages.Helpers/Messages.Helpers.csproj
new file mode 100644
index 0000000..4641dbd
--- /dev/null
+++ b/Messages.Helpers/Messages.Helpers.csproj
@@ -0,0 +1,5 @@
+
+
+ netstandard2.0
+
+
diff --git a/Messages.Api/Helpers/StringExtensions.cs b/Messages.Helpers/StringExtensions.cs
similarity index 98%
rename from Messages.Api/Helpers/StringExtensions.cs
rename to Messages.Helpers/StringExtensions.cs
index c41ff55..aa46131 100644
--- a/Messages.Api/Helpers/StringExtensions.cs
+++ b/Messages.Helpers/StringExtensions.cs
@@ -2,7 +2,7 @@
using System.Globalization;
using System.Text;
-namespace Messages.Api.Helpers
+namespace Messages.Helpers
{
public static class StringExtensions
{
diff --git a/Messages.Tests/Helpers/PalindromeTests.cs b/Messages.Tests/Helpers/PalindromeTests.cs
index b0485dc..5381f2a 100644
--- a/Messages.Tests/Helpers/PalindromeTests.cs
+++ b/Messages.Tests/Helpers/PalindromeTests.cs
@@ -1,4 +1,4 @@
-using Messages.Api.Helpers;
+using Messages.Helpers;
using System;
using Xunit;