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

vlib.x: add a go like benchmark, that estimates automatically how many iterations are needed, to get a statistically significant result #22215

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

skeris
Copy link
Contributor

@skeris skeris commented Sep 13, 2024

For my task, I need a benchmark that measures memory consumption. I checked the default benchmark library and didn't find that feature. So I decided to write it myself.

As advised in the Telegram chat, "just rewrite the golang library to vlang".

I checked the golang benchmark code and decided it was strange and overly complicated due to its use as a command-line tool.

So I decided to create my own library.

Basically, I copied the memory measurement logic and the prediction of the number of iterations from golang to estimate the expected benchmark evaluation time. And from vlang, I got the logic of using the benchmark as a library, not as a command-line tool.

How to use it:

  • Create a Benchmark using the constructor, provide a closure to benchmark, optionally provide the expected number of iterations or estimation time.
  • Run the run_benchmark method.
  • Wait until it ends.
  • Use BenchmarkResult as you need - by default, it prints, but you can send it to a chat or to a database.

But I'm not sure if I'm using the gc_heap_usage fields correctly. I was confused by the boehm_gc documentation, it's too hard for me. So if anyone can help me with that - you are welcome

@Delta456
Copy link
Member

There's already a benchmark library. How different is it from that library?

@JalonSolov
Copy link
Contributor

The current benchmark library only measures speed, not memory.

@spytheman
Copy link
Member

There are other differences too - the existing benchmark does not auto calibrate the number of iterations, till a given time passes, it relies on your code to run the loop and iterate manually.

@spytheman spytheman changed the title Feat go like benchmark vlib.x: add a go like benchmark, that estimates automatically how many iterations are needed, to get a statistically significant result Sep 22, 2024
- create params struct to make more convinient way to create benchmark
- make err messages more clear
@spytheman spytheman merged commit c72dde2 into vlang:master Sep 23, 2024
67 checks passed
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.

4 participants