Skip to content

yoav-lavi/benchmark-scratchpad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Benchmark Scratchpad

A quick scratchpad for benchmarking Rust code

Prerequisites

Instructions

  1. Edit benches/benchmark.rs
  2. Run cargo make bench

benchmarks!

The benchmarks! macro accepts input with the following structure:

benchmarks! {
  benchmark_name { /* benchmark impl */ }
  other_benchmark_name { /* other benchmark impl */ }
}

The criterion.rs black_box function is included and usable within the macro.

criterion::black_box stops the compiler from constant-folding away the whole function and replacing it with a constant.

You can you the keyword @skip before a benchmark for it not to be run:

benchmarks! {
  @skip benchmark_name { /* benchmark impl */ }
}

Tasks

  • cargo make bench - runs the benchmark via cargo-criterion
  • cargo make bench-verbose - runs the benchmark via cargo-criterion with verbose output
  • cargo make reset - resets the criterion data for earlier benchmarks
  • cargo make new - returns benches/benchmark.rs to the initial state
  • cargo make save [FILENAME] - saves the contents of benches/benchmark.rs to saved/[FILENAME].rs

Example

mod internals;

benchmarks! {
    collect_vec_string {
        let vector = black_box(vec!["hello", "world"]);
        let _output = vector
            .iter()
            .map(|item| item.to_uppercase())
            .collect::<Vec<String>>()
            .join("");
    }

    collect_string {
        let vector = black_box(vec!["hello", "world"]);
        let _output = vector
            .iter()
            .map(|item| item.to_uppercase())
            .collect::<String>();
    }
}

Uses

About

A quick scratchpad for benchmarking Rust code

Topics

Resources

License

Stars

Watchers

Forks

Languages