-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks using BenchmarkDotNet
It runs with all supported runtimes It uses memory diagnoser to check allocations
- Loading branch information
Showing
4 changed files
with
68 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
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,19 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Sqids.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class EncodeBenchmark | ||
{ | ||
#if NET7_0_OR_GREATER | ||
private SqidsEncoder<int> _encoder = new SqidsEncoder<int>(); | ||
#else | ||
private SqidsEncoder _encoder = new SqidsEncoder(); | ||
#endif | ||
|
||
[Benchmark] | ||
public string Encode() => _encoder.Encode(42); | ||
|
||
[Benchmark] | ||
public IReadOnlyList<int> Decode() => _encoder.Decode("Jg"); | ||
} |
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,20 @@ | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Environments; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Sqids.Benchmarks; | ||
|
||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
IConfig config = ManualConfig.CreateMinimumViable() | ||
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net472)) | ||
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60)) | ||
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core70)) | ||
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80)); | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); | ||
} | ||
} |
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<!-- NOTE: `net472` is used for testing `netstandard2.0` --> | ||
<TargetFrameworks>net472;net6.0;net7.0;net8.0</TargetFrameworks> | ||
<LangVersion>12.0</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<OutputType>exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sqids\Sqids.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" /> | ||
</ItemGroup> | ||
|
||
</Project> |