Questions tagged [rust-criterion]

16 questions
12
votes
1 answer

Is it possible to limit the number of iterations that Criterion performs?

I am developing some benchmarks for a crate using criterion (cargo bench). I would like to temporarily limit the amount of iterations until I finish the code. I know measurements may not be precise, but this is just temporary. Is this possible?
Juan Leni
  • 6,982
  • 5
  • 55
  • 87
4
votes
0 answers

Long build times for Criterion cargo bench but not cargo build --release with large type

While working on a Brainfuck interpreter in Rust, I noticed that cargo bench takes an incredibly long time to build a Criterion bench when the Benchmark contains a large type. As part of my Brainfuck implementation, I define a structure with a very…
Rafael
  • 182
  • 1
  • 9
4
votes
1 answer

Rust Criterion benchmarking modules `unresolved import `crate::some_module``

I have a binary project with a lot of internal modules to organise functionality. I'm trying to get Criterion working for benchmarks. The error: error[E0432]: unresolved import `crate::some_module` --> benches/benchmarks.rs:3:5 | 3 | use…
Jonathan Woollett-light
  • 2,813
  • 5
  • 30
  • 58
4
votes
1 answer

Where is Criterion's output, or how do I enable it?

The Criterion benchmarking library for Rust is documented as generating plots describing the benchmark results: Criterion.rs can generate a number of useful charts and graphs which you can check to get a better understanding of the behavior of the…
Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
3
votes
1 answer

Github Action can't comment on PR

I am using a github action that compares benchmark results and posts them as a comment on the PR. This is the actions file - https://github.com/smrpn/criterion-compare-action/blob/move_to_actions/main.js it says - try { await…
eth_sign
  • 63
  • 7
2
votes
1 answer

Can't import my crate into criterion benchmark

I'm trying to use the criterion crate to benchmark a function in my binary crate. use criterion::{black_box, criterion_group, criterion_main, Criterion}; use rand::Rng; use enigma::enigma::Enigma; // failed to resolve: use of undeclared crate or…
Brandon Piña
  • 614
  • 1
  • 6
  • 20
2
votes
1 answer

How to create randomized inputs for Criterion benchmarks in Rust

I am trying to benchmark the annotate routine using the Criterion benchmarking library. The routine is checking a &[&str] parameter (2D square string) and returns Vec and I suspect that its execution time might depend on the contents of the…
Vemulo
  • 404
  • 5
  • 14
2
votes
1 answer

Compile error when running cargo bench (criterion/serde)

I added following lines to the cargo.toml of my project in order to benchmark my code: [dev-dependencies] criterion = "0.3" [[bench]] name = "samples" harness = false After running cargo bench, I get a lot of errors similar to the…
CoronA
  • 7,717
  • 2
  • 26
  • 53
2
votes
0 answers

Import a module from my crate in a Criterion benchmark

I would like to benchmark functions created in my module, but I don't understand how I can import the module to then use the functions. My folders structure is the following project |-benches |-benchmarks.rs |-src |-one |-mod.rs …
Astinog
  • 1,151
  • 3
  • 12
  • 35
1
vote
1 answer

rust Criterion won't create HTML report

I'm following along the rust Criterion book on how to benchmark a function and plot the results as the size of the input grows. Both the book and documentation however are quite sparse in giving actual examples on how to plot the benchmark result.…
Max
  • 2,072
  • 5
  • 26
  • 42
1
vote
1 answer

Rust (criterion): how to pass mutable reference within bench_with_input()

I am new to Rust and am trying to benchmark sorting algorithms. The functions take immutable references to a slice (fn sort(&self, slice: &mut [T])). I am trying to use the criterion crate to benchmark them for different inputs (random vectors of…
FISR
  • 13
  • 1
  • 5
1
vote
2 answers

Benchmark function with input that doesn't implement the Copy trait

I am running benchmarks with Criterion but am facing issues with functions that have an input that does not implement the Copy trait. For example, I have set up the following benchmark for a function with the signature pub fn hash(vector: Vec<&str>)…
bergwald
  • 88
  • 1
  • 7
1
vote
2 answers

Trouble Benchmarking actix_web api with Criterion

I have been trying to add benchmarking using the Criterion crate to my actix_web application. I have been struggling to get it to work because the AsyncExecutor trait is not implemented for tokio 0.2.x. I tried implementing the trait for the…
Marcus Ruddick
  • 9,795
  • 7
  • 28
  • 43
1
vote
0 answers

How to bench a function with a #[test] attribute with Criterion

I want to bench a function with criterion crate, this function is also a test function. It seems not to be possible to call the function during benchmarking when the #[test] attribute is present. #[test] fn verify_encryption() { // ... } A…
Ostn
  • 803
  • 1
  • 9
  • 27
0
votes
1 answer

Add logs to cargo bench

I'm using the criterion library to benchmark some code and am in need of printing logs via the log crate. I ran the following command on this snippet of code: cargo bench --bench my_benchmark warn!("Please warn"); println!("Please print"); But…
Max
  • 2,072
  • 5
  • 26
  • 42
1
2