Skip to content

Added Benchmark project comparing performance of 3.1.0 vs 3.2.0 (encode and decode)#45

Open
loudenvier wants to merge 12 commits intosqids:mainfrom
loudenvier:main
Open

Added Benchmark project comparing performance of 3.1.0 vs 3.2.0 (encode and decode)#45
loudenvier wants to merge 12 commits intosqids:mainfrom
loudenvier:main

Conversation

@loudenvier
Copy link
Copy Markdown
Contributor

This PR introduces a new Sqids.Benchmarks project to the solution, providing initial performance benchmarks for both encoding and decoding operations.

Key Details

  • Includes a custom BenchmarkDotNet configuration.
  • Adds conditional project variables to reference both old and new package versions, enabling fair performance comparisons across releases.
  • Benchmarks encode/decode of int.MaxValue, using either int or long depending on availability of long support:
    • Fully supported in v3.2.0.
    • Available only in the generic version of v3.1.0.
  • Ensures consistent input across versions for accurate comparison.

Results

  • Performance impact is negligible in both speed and memory usage.
Method Runtime Arguments Mean Error StdDev Gen0 Allocated
SqidEncode .NET 7.0 /p:BenchmarksPackageVersion=3.1.0 13,515.13 ns 137.628 ns 122.004 ns 0.6866 11680 B
SqidDecode .NET 7.0 /p:BenchmarksPackageVersion=3.1.0 94.89 ns 0.334 ns 0.313 ns 0.0052 88 B
SqidEncode .NET 7.0 /p:BenchmarksPackageVersion=3.2.0 13,846.03 ns 93.602 ns 73.079 ns 0.6866 11712 B
SqidDecode .NET 7.0 /p:BenchmarksPackageVersion=3.2.0 97.26 ns 1.931 ns 1.896 ns 0.0052 88 B
SqidEncode .NET 8.0 /p:BenchmarksPackageVersion=3.1.0 8,690.65 ns 40.099 ns 37.508 ns 0.6866 11680 B
SqidDecode .NET 8.0 /p:BenchmarksPackageVersion=3.1.0 81.46 ns 0.659 ns 0.584 ns 0.0052 88 B
SqidEncode .NET 8.0 /p:BenchmarksPackageVersion=3.2.0 8,729.78 ns 73.010 ns 68.293 ns 0.6866 11680 B
SqidDecode .NET 8.0 /p:BenchmarksPackageVersion=3.2.0 80.47 ns 0.084 ns 0.075 ns 0.0052 88 B
SqidEncode .NET Framework 4.8 /p:BenchmarksPackageVersion=3.1.0 50,760.07 ns 243.170 ns 227.461 ns 1.8311 11714 B
SqidDecode .NET Framework 4.8 /p:BenchmarksPackageVersion=3.1.0 459.91 ns 0.476 ns 0.398 ns 0.0124 80 B
SqidEncode .NET Framework 4.8 /p:BenchmarksPackageVersion=3.2.0 51,174.86 ns 172.228 ns 161.102 ns 1.8311 11899 B
SqidDecode .NET Framework 4.8 /p:BenchmarksPackageVersion=3.2.0 533.62 ns 2.948 ns 2.758 ns 0.0439 281 B

Notes

  • During repo sync after the previous PR merge, ~12 extra commits appeared, but they contain no actual changes. This should not negatively affect the repository.
  • No modifications were made to the core codebase.
  • No new NuGet package is required.

Added support for all integral types in legacy frameworks.
…urce generation

Introduces an incremental source generator for SqidsEncoder that adds overloads supporting all integral types on legacy frameworks.

Updates README with usage details, adds new tests for legacy encoding/decoding, and wires up the code generation project in the solution and main project.

This enables drop-in support for byte, sbyte, short, ushort, int, uint, long, and ulong encoding/decoding in .NET Standard 2.0 (.NET Framework 4.7.2+) and .NET 6 environments.

Extreme care was taken to avoid structural and code changes to the SqidsEncoder class (even comments were kept where they were, as a diff will show) to make it easy to keep it up to date with the main Sqids project if a PR is not accepted.
Updated the GitHub Actions workflow to run on Windows and added support for multiple .NET versions.
Updated the .NET workflow to install multiple .NET versions and simplified the setup steps.
Introduces a new Sqids.Benchmarks project to the solution for performance testing. Includes a custom BenchmarkDotNet config and custom project variables that allow referencing the old and new versions of the package conditionally, and also allow to create conditional code based on these variables to properly compare performance across versions of the package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant