Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add benchmarks #29

wants to merge 2 commits into from

Conversation

Genbox
Copy link
Contributor

@Genbox Genbox commented Jan 21, 2024

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.

It runs with all supported runtimes
It uses memory diagnoser to check allocations
@Genbox
Copy link
Contributor Author

Genbox commented Jan 21, 2024

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

@aradalvand
Copy link
Collaborator

aradalvand commented Jan 30, 2024

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

@aradalvand
Copy link
Collaborator

And also this one?

@Genbox
Copy link
Contributor Author

Genbox commented Jan 30, 2024

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.

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.

None yet

2 participants