Skip to content
Open
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
6 changes: 6 additions & 0 deletions Sqids.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sqids.Tests", "test\Sqids.T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sqids.CodeGeneration", "src\Sqids.CodeGeneration\Sqids.CodeGeneration.csproj", "{04A8CCFC-1496-4F22-8399-922367E9260B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sqids.Benchmarks", "benchmarks\Sqids.Benchmarks\Sqids.Benchmarks.csproj", "{44F4CB35-FD25-4D58-DB03-F1539F678FF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,6 +32,10 @@ Global
{04A8CCFC-1496-4F22-8399-922367E9260B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04A8CCFC-1496-4F22-8399-922367E9260B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04A8CCFC-1496-4F22-8399-922367E9260B}.Release|Any CPU.Build.0 = Release|Any CPU
{44F4CB35-FD25-4D58-DB03-F1539F678FF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44F4CB35-FD25-4D58-DB03-F1539F678FF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44F4CB35-FD25-4D58-DB03-F1539F678FF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44F4CB35-FD25-4D58-DB03-F1539F678FF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/Sqids.Benchmarks/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{cs,vb}]
dotnet_diagnostic.CA1050.severity = none
67 changes: 67 additions & 0 deletions benchmarks/Sqids.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;

BenchmarkRunner.Run<SquidsBenchmarks>();

// Define the Custom Config
public class PackageComparisonConfig : ManualConfig
{
public PackageComparisonConfig() {
var packageVersions = new[] { "3.2.0", "3.1.0" };

var runtimes = new Runtime[]
{
ClrRuntime.Net48,
CoreRuntime.Core70,
CoreRuntime.Core80
};

foreach (var version in packageVersions) {
foreach (var runtime in runtimes) {
AddJob(Job.Default
.WithRuntime(runtime)
.WithMsBuildArguments($"/p:BenchmarksPackageVersion={version}")
.WithId($"{runtime.Name} - v{version}"));
}
}
}
}

[Config(typeof(PackageComparisonConfig))]
[MemoryDiagnoser]
public class SquidsBenchmarks
{
#if NET7_0_OR_GREATER
private readonly Sqids.SqidsEncoder<long> sqid = new();
#else
private readonly Sqids.SqidsEncoder sqid = new();
#endif

#if WITH_LONG_SUPPORT
static readonly long longValue = (long)int.MaxValue;
#else
static readonly int intValue = int.MaxValue;
#endif

static readonly string EncodedValue = "UKrsQ1F";

[Benchmark]
public string SqidEncode() {
#if WITH_LONG_SUPPORT
var encoded = sqid.Encode(longValue);
#else
var encoded = sqid.Encode(intValue);
#endif
return encoded;
}

[Benchmark]
public void SqidDecode() {
var decoded = sqid.Decode(EncodedValue)[0];
if (decoded != int.MaxValue)
throw new Exception("Decoded value does not match original");
}
}
31 changes: 31 additions & 0 deletions benchmarks/Sqids.Benchmarks/Sqids.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net48;net7.0;net8.0</TargetFrameworks>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<BenchmarksPackageVersion Condition="'$(BenchmarksPackageVersion)' == ''">3.2.0</BenchmarksPackageVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(BenchmarksPackageVersion)' == '3.2.0'">
<DefineConstants>$(DefineConstants);WITH_LONG_SUPPORT</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
<PackageReference Include="Sqids" Version="$(BenchmarksPackageVersion)" />
</ItemGroup>

<ItemGroup>
<EditorConfigFiles Remove="C:\work\GitHub\sqids-dotnet\benchmarks\Sqids.Benchmarks\.editorconfig" />
</ItemGroup>

<ItemGroup>
<None Include="C:\work\GitHub\sqids-dotnet\benchmarks\Sqids.Benchmarks\.editorconfig" />
</ItemGroup>

</Project>
Loading