sqids-dotnet icon indicating copy to clipboard operation
sqids-dotnet copied to clipboard

Add benchmarks

Open Genbox opened this issue 1 year ago • 4 comments

Added a benchmark project using BenchmarkDotNet which measures a few scenarios on all supported runtimes. The scenarios are:

  • Encoding a small integer
  • Encoding a large integer
  • Encoding multiple integers

The same cases are covered for decoding. The project is currently using a benchmark switcher to make space for future benchmarks, but feel free to change it to just run the one benchmark.

Genbox avatar Jan 21 '24 12:01 Genbox

I've created an example optimization in this commit.

It uses a local stack-based buffer instead of a StringBuilder. Notice how the allocations are cut in half for EncodeSmall.

Before: image

After: image

Genbox avatar Jan 21 '24 12:01 Genbox

@Genbox Could you please make a PR for this commit as well?

aradalvand avatar Jan 30 '24 19:01 aradalvand

And also this one?

aradalvand avatar Jan 30 '24 19:01 aradalvand

Yep. I'll get right on it. Note that the stack buffer one seems to work, but I'm unsure if the size of the buffer is enough. I did create a function that calculates the length needed before doing the work, but it was slower on a few of the platforms and didn't really save much allocation.

Genbox avatar Jan 30 '24 21:01 Genbox