-
Notifications
You must be signed in to change notification settings - Fork 319
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
How to benchmark a function from my crate #353
Comments
Hey, thanks for trying Criterion.rs! Unfortunately, it's not currently possible to use Criterion.rs with binary crates, only with library crates (see this issue for more details). If you have a library crate, you can take a look at the Getting Started page of the user guide, which shows an example of benchmarking a function from the Edit: I almost forgot; this is documented in the Known Limitations section of the user guide. Edit2: It's fairly common for binary crates in Rust to contain only a thin layer of glue code (parsing command-line arguments, etc.) around a library crate that implements the application logic. I don't actually remember just off-hand why that's done, but it does handily solve this problem. |
Thanks for that reply! I'll have to read up on the difference between creating a lib vs binary crate (I'm kinda new to rust), but it does sound like I should be able do do what your Edit2 suggests |
Okay. Turns out I would have needed to use a library instead of a binary crate anyways, because I want to use my crate in a different crate and it is not possible to use binary crates in other crates. So thank you for the suggestion! I don't see the point of binary crates then... because libraries can have executables with For anybody else with the same problem though: All it takes is renaming |
I got the fibonacci example to work with the function within
my_benchmark.rs
. But I cannot figure out how I can benchmark a function that I defined in my own crate.My folder structure is like this:
How could I benchmark a function that is defined in
main.rs
?Or is that already documented somewhere? In that case, I think a more obvious link is needed
The text was updated successfully, but these errors were encountered: