Code Monkey home page Code Monkey logo

diol's Introduction

diol is a benchmarking library for rust.

getting started

add the following to your Cargo.toml.

[dev-dependencies]
diol = "0.6.0"
[[bench]]
name = "my_benchmark"
harness = false

then in benches/my_benchmark.rs.

use diol::prelude::*;
fn main() -> std::io::Result<()> {
    let mut bench = Bench::new(BenchConfig::from_args()?);
    bench.register(slice_times_two, [4, 8, 16, 128, 1024]);
    bench.run()?;
    Ok(())
}
fn slice_times_two(bencher: Bencher, len: usize) {
    let mut v = vec![0.0_f64; len];
    bencher.bench(|| {
        for x in &mut v {
            *x *= 2.0;
        }
        black_box(&mut v);
    });
}

run the benchmark with cargo bench, or cargo bench --bench my_benchmark if you have multiple benchmarks you can also pass in benchmark options using cargo bench --bench my_benchmark -- [OPTIONS...]

╭─────────────────┬──────┬───────────┬───────────┬───────────┬───────────╮
│ benchmark       │ args │   fastest │    median │      mean │    stddev │
├─────────────────┼──────┼───────────┼───────────┼───────────┼───────────┤
│ slice_times_two │    4 │  29.61 ns │  34.38 ns │  34.83 ns │   1.62 ns │
├─────────────────┼──────┼───────────┼───────────┼───────────┼───────────┤
│ slice_times_two │    8 │  44.17 ns │  53.04 ns │  53.32 ns │   3.25 ns │
├─────────────────┼──────┼───────────┼───────────┼───────────┼───────────┤
│ slice_times_two │   16 │  93.66 ns │ 107.91 ns │ 108.13 ns │   4.11 ns │
├─────────────────┼──────┼───────────┼───────────┼───────────┼───────────┤
│ slice_times_two │  128 │ 489.97 ns │ 583.59 ns │ 585.28 ns │  33.15 ns │
├─────────────────┼──────┼───────────┼───────────┼───────────┼───────────┤
│ slice_times_two │ 1024 │   3.77 µs │   4.51 µs │   4.53 µs │ 173.44 ns │
╰─────────────────┴──────┴───────────┴───────────┴───────────┴───────────╯

dependencies

the plotters dependency requires the pkg-config, freetype and fontconfig.
to install on Ubuntu, you can use the following command.

sudo apt install pkg-config libfreetype6-dev libfontconfig1-dev

diol's People

Contributors

o-x-e-y avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

gu1nness o-x-e-y

diol's Issues

Is there a way to test private functions?

Hi, thanks for your great work! This is my favorite benchmarking library so far.

But I wonder, is there a way to test private functions? For example, I have a crate which has 1 public function as it's API, but on this function call it determines which internal implementation to use. I would like to bench those internal implementations without making them public.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.