• Stars
    star
    895
  • Rank 51,027 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast and simple benchmarking for Rust projects

Divan

docs.rs badge Downloads badge GitHub stars badge CI build status badge

Comfy benchmarking for Rust projects, brought to you by Nikolai Vazquez.

Guide

A guide is being worked on. In the meantime, see announcement post.

Getting Started

  1. Add the following to your project's Cargo.toml:

    [dev-dependencies]
    divan = "0.1.7"
    
    [[bench]]
    name = "example"
    harness = false
  2. Create a benchmarks file at benches/example.rs1 with your benchmarking code:

    fn main() {
        // Run registered benchmarks.
        divan::main();
    }
    
    // Define a `fibonacci` function and register it for benchmarking.
    #[divan::bench]
    fn fibonacci() -> u64 {
        fn compute(n: u64) -> u64 {
            if n <= 1 {
                1
            } else {
                compute(n - 2) + compute(n - 1)
            }
        }
    
        compute(divan::black_box(10))
    }
  3. Run your benchmarks with cargo bench:

    example       fastest  β”‚ slowest β”‚ median   β”‚ mean     β”‚ samples β”‚ iters
    ╰─ f​ibonacci  196.1 ns β”‚ 217 ns  β”‚ 197.5 ns β”‚ 198.1 ns β”‚ 100     β”‚ 3200

See #[divan::bench] for info on benchmark function registration.

Examples

Practical example benchmarks can be found in the examples/benches directory. These can be benchmarked locally by running:

git clone https://github.com/nvzqz/divan.git
cd divan

cargo bench -q -p examples --all-features

More thorough usage examples can be found in the #[divan::bench] documentation.

License

Like the Rust project, this library may be used under either the MIT License or Apache License (Version 2.0).

Footnotes

  1. Within your crate directory, i.e. $CARGO_MANIFEST_DIR ↩

More Repositories

1

FileKit

Simple and expressive file management in Swift
Swift
2,289
star
2

RandomKit

Random data generation in Swift
Swift
1,473
star
3

static-assertions

Ensure correct assumptions about constants, types, and more in Rust
Rust
566
star
4

Sage

A cross-platform chess library for Swift
Swift
376
star
5

impls

A Rust macro to determine if a type implements a logical trait expression
Rust
246
star
6

Menubar-Colors

A macOS app for convenient access to the system color panel
Swift
175
star
7

fruity

Rusty bindings for Apple libraries
Rust
169
star
8

swift-bindgen

Bridging the gap between Swift and Rust
Rust
149
star
9

Unreachable

Unreachable code path optimization hint for Swift
Swift
103
star
10

Threadly

Type-safe thread-local storage in Swift
Swift
74
star
11

condtype

Choose Rust types at compile-time via constants
Rust
59
star
12

embed-plist-rs

Embed property list files like Info.plist directly in your Rust executable binary
Rust
39
star
13

Roman

Seamless Roman numeral conversion in Swift
Swift
36
star
14

rosy

Rust and Ruby, sitting in a tree 🌹
Rust
23
star
15

byte-set-rs

Efficient sets of bytes for Rust
Rust
19
star
16

cargo-emit

Talk to Cargo easily at build time
Rust
16
star
17

Clockmoji

Simple and intuitive time formatting using clock emoji.
Swift
13
star
18

XO

A cross-platform tic-tac-toe library for Swift
Swift
13
star
19

Lazy

Save the hard work for later, lazily evaluate values anywhere
Swift
12
star
20

Weak

Weak and Unowned as native Swift types
Swift
10
star
21

typebool

Type-level booleans in Rust for compile-time hackery
Rust
8
star
22

c-utf8-rs

UTF-8 encoded C strings for Rust
Rust
6
star
23

malloced

A malloc-ed box pointer type for Rust
Rust
5
star
24

dotfiles

Personal dotfiles
Shell
5
star
25

aloxide

Compile Rubies on Linux, macOS, and Windows
Rust
5
star
26

mods

Simpler Rust module declaration
Rust
5
star
27

bit-collection-rs

Iterate over bits in Rust
Rust
5
star
28

unsafe-unwrap-rs

Unsafely unwrap Result and Option types without checking in Rust
Rust
5
star
29

uncon-rs

Unchecked and unsafe type conversions in Rust
Rust
4
star
30

head-rs

Common Rust types with inline headers, such as HeaderVec for Vec
Rust
4
star
31

bad-rs

Unlicensed bad ideas
Rust
4
star
32

rust-workshop

A workshop on the Rust programming language
3
star
33

OneOrMore

A Swift collection of one or more elements
Swift
3
star
34

fmty

Rust library of composable `core::fmt` utilities
Rust
3
star
35

mem-cmp-rs

Safe memory comparison between types in Rust
Rust
2
star
36

ShiftOperations

A Β΅framework for a needed ShiftOperations protocol that does not appear in the Swift standard library
Swift
1
star
37

rust-selector-example

My attempt at creating Objective-C selectors in Rust at compile time
Shell
1
star
38

asygnal

Handle signals (e.g. ctrl-c) efficiently and asynchronously in Rust
Rust
1
star
39

chance-rs

Random number generation in Rust
Rust
1
star