Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Last active January 13, 2021 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justanotherdot/0b0051f96bdeb44c25ad58998910f6a1 to your computer and use it in GitHub Desktop.
Save justanotherdot/0b0051f96bdeb44c25ad58998910f6a1 to your computer and use it in GitHub Desktop.
Drop in benchmark snippet for Rust projects that want to use cargo-bench on nightly.
// NB. this must be placed at the top of the module.
#![feature(test)]
#[cfg(test)]
mod tests {
extern crate test;
use super::*;
use test::{black_box, Bencher};
#[bench]
fn bench_x(b: &mut Bencher) {
b.iter(|| {
for i in 1..2 {
black_box(());
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment