-
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.
* Added Benchmark project to solution * Added BenchmarkDotNet NuGet reference * Added sample benchmark --------- Co-authored-by: Marcin Przywóski <[email protected]>
- Loading branch information
1 parent
2514f0c
commit 266c33f
Showing
3 changed files
with
63 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.0" /> | ||
</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,37 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace ExportViewer.Benchmarks | ||
{ | ||
public class Program | ||
{ | ||
static void Main (string[] args) | ||
{ | ||
var summary = BenchmarkRunner.Run<Program>(); | ||
} | ||
|
||
private const string TestString = "Hello, World!"; | ||
|
||
[Benchmark] | ||
public void UseStringBuilder () | ||
{ | ||
var sb = new System.Text.StringBuilder(); | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
sb.Append(TestString); | ||
} | ||
|
||
_ = sb.ToString(); | ||
} | ||
|
||
[Benchmark] | ||
public void UseStringConcatenation () | ||
{ | ||
string result = ""; | ||
for (int i = 0; i < 1000; i++) | ||
{ | ||
result += TestString; | ||
} | ||
} | ||
} | ||
} |
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