-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from markcastle/feature/benchmarking_and_improving
Feature/benchmarking and improving
- Loading branch information
Showing
15 changed files
with
904 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
image: Visual Studio 2019 | ||
image: Visual Studio 2022 | ||
|
||
before_build: | ||
- nuget restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CaseConverter\CaseConverter.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace CaseConverter.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class CaseConverterBenchmarks | ||
{ | ||
private const string TestString = "ThisIsATestString"; | ||
private const string TestString2 = "thisisateststring"; | ||
|
||
private const string LongTestString = | ||
"This method appears to be efficient already as it utilizes regular expressions, which are highly performant for string operations such as this. However, if you would like an alternative approach that remains compatible with .NET Standard 2.0 and 2.1, you can use a StringBuilder to build a new string while iterating over the input string's characters:"; | ||
|
||
[Benchmark] | ||
public string ToSnakeCaseBenchmark() | ||
{ | ||
return TestString.ToSnakeCase(); | ||
} | ||
|
||
[Benchmark] | ||
public string ToCamelCaseBenchmark() | ||
{ | ||
return TestString.ToCamelCase(); | ||
} | ||
|
||
[Benchmark] | ||
public string ToKebabCaseBenchmark() | ||
{ | ||
return TestString.ToKebabCase(); | ||
} | ||
|
||
[Benchmark] | ||
public string ToPascalCaseBenchmark() | ||
{ | ||
return TestString2.ToPascalCase(); | ||
} | ||
|
||
[Benchmark] | ||
public string ToTitleCaseBenchmark() | ||
{ | ||
return TestString.ToTitleCase(); | ||
} | ||
|
||
[Benchmark] | ||
public string ToTrainCaseBenchmark() | ||
{ | ||
return TestString.ToTrainCase(); | ||
} | ||
|
||
[Benchmark] | ||
public bool IsAllUpperBenchmark() | ||
{ | ||
return TestString.IsAllUpper(); | ||
} | ||
|
||
[Benchmark] | ||
public string ReplaceWhitespaceBenchmark() | ||
{ | ||
return LongTestString.ReplaceWhitespace("."); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using BenchmarkDotNet.Reports; | ||
using BenchmarkDotNet.Running; | ||
using CaseConverter.Benchmarks; | ||
|
||
Summary summary = BenchmarkRunner.Run<CaseConverterBenchmarks>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
CaseConverter.Tests/InsertCharacterBeforeUpperCaseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace CaseConverter.Tests | ||
{ | ||
[TestClass] | ||
public class InsertCharacterBeforeUpperCaseTests | ||
{ | ||
[TestMethod] | ||
public void TestInsertSpaceBeforeUpperCase() | ||
{ | ||
string input = "InsertCharacterBeforeUpperCase"; | ||
string expectedOutput = "Insert Character Before Upper Case"; | ||
string actualOutput = input.InsertCharacterBeforeUpperCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestInsertUnderscoreBeforeUpperCase() | ||
{ | ||
string input = "InsertCharacterBeforeUpperCase"; | ||
string expectedOutput = "Insert_Character_Before_Upper_Case"; | ||
string actualOutput = input.InsertCharacterBeforeUpperCase('_'); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEmptyString() | ||
{ | ||
string input = ""; | ||
string expectedOutput = ""; | ||
string actualOutput = input.InsertCharacterBeforeUpperCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAllLowerCase() | ||
{ | ||
string input = "insertcharacterbeforeuppercase"; | ||
string expectedOutput = "insertcharacterbeforeuppercase"; | ||
string actualOutput = input.InsertCharacterBeforeUpperCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAllUpperCase() | ||
{ | ||
string input = "INSERTCHARACTERBEFOREUPPERCASE"; | ||
string expectedOutput = "I N S E R T C H A R A C T E R B E F O R E U P P E R C A S E"; | ||
string actualOutput = input.InsertCharacterBeforeUpperCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace CaseConverter.Tests | ||
{ | ||
[TestClass] | ||
public class ToCamelCaseTests | ||
{ | ||
[TestMethod] | ||
public void TestBasicString() | ||
{ | ||
string input = "hello world"; | ||
string expectedOutput = "helloWorld"; | ||
string actualOutput = input.ToCamelCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestHyphenatedString() | ||
{ | ||
string input = "hello-world"; | ||
string expectedOutput = "helloWorld"; | ||
string actualOutput = input.ToCamelCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestUnderscoreString() | ||
{ | ||
string input = "hello_world"; | ||
string expectedOutput = "helloWorld"; | ||
string actualOutput = input.ToCamelCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPreserveLeadingUnderscore() | ||
{ | ||
string input = "_hello_world"; | ||
string expectedOutput = "_helloWorld"; | ||
string actualOutput = input.ToCamelCase(preserveLeadingUnderscore: true); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRemoveWhitespace() | ||
{ | ||
string input = "hello world"; | ||
string expectedOutput = "helloWorld"; | ||
string actualOutput = input.ToCamelCase(removeWhitespace: true); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPreserveWhitespace() | ||
{ | ||
string input = "hello world"; | ||
string expectedOutput = "hello world"; | ||
string actualOutput = input.ToCamelCase(removeWhitespace: false); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEmptyString() | ||
{ | ||
string input = ""; | ||
string expectedOutput = ""; | ||
string actualOutput = input.ToCamelCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAllUpperCase() | ||
{ | ||
string input = "HELLO_WORLD"; | ||
string expectedOutput = "helloWorld"; | ||
string actualOutput = input.ToCamelCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace CaseConverter.Tests | ||
{ | ||
[TestClass] | ||
public class ToKebabCaseTests | ||
{ | ||
[TestMethod] | ||
public void TestToKebabCase() | ||
{ | ||
string input = "This is a test"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToKebabCaseWithSpaces() | ||
{ | ||
string input = "This is a test"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToKebabCaseWithUnderscores() | ||
{ | ||
string input = "this_is_a_test"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToKebabCaseWithHyphens() | ||
{ | ||
string input = "this-is-a-test"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEmptyString() | ||
{ | ||
string input = ""; | ||
string expectedOutput = ""; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAllUpperCase() | ||
{ | ||
string input = "THIS IS A TEST"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestAllLowerCase() | ||
{ | ||
string input = "this is a test"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestPascalCase() | ||
{ | ||
string input = "ThisIsATest"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
|
||
[TestMethod] | ||
public void TestCamelCase() | ||
{ | ||
string input = "thisIsATest"; | ||
string expectedOutput = "this-is-a-test"; | ||
string actualOutput = input.ToKebabCase(); | ||
Assert.AreEqual(expectedOutput, actualOutput); | ||
} | ||
} | ||
} |
Oops, something went wrong.