百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

divan

> 数据库
开源

针对 Rust 项目的快速、简单的基准测试

1.4K stars0 点赞1 次浏览
访问官网GitHub

工具介绍

针对 Rust 项目的快速、简单的基准测试

Sponsor

If you or your company find Divan valuable, consider sponsoring on GitHub or donating via PayPal. Sponsorships help me progress on what's possible with benchmarking in Rust.

Guide

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

  • Announcement post
  • "Proving Performance" FOSDEM talk

Getting Started

Divan 0.1.21 requires Rust 1.80.0 or later.

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

    toml
    [dev-dependencies]
    divan = "0.1.21"
    
    [[bench]]
    name = "example"
    harness = false
  2. Create a benchmarks file at benches/example.rs[^1] with your benchmarking code:

    rust
    fn main() {
        // Run registered benchmarks.
        divan::main();
    }
    
    // Register a `fibonacci` function and benchmark it over multiple cases.
    #[divan::bench(args = [1, 2, 4, 8, 16, 32])]
    fn fibonacci(n: u64) -> u64 {
        if n <= 1 {
            1
        } else {
            fibonacci(n - 2) + fibonacci(n - 1)
        }
    }
  3. Run your benchmarks with cargo bench:

…

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

Checking benchmarks in CI

If you want to run each benchmarked function only once (to check that they don't panic without measuring their performance), you can run the benchmark runner crate with the --test parameter. You can do so by running either

bash
cargo bench -- --test

or

bash
cargo test --benches

Examples

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

bash
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).

[^1]: Within your crate directory, i.e. $CARGO_MANIFEST_DIR

Issues· 51 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustbenchmarkfastperformancerust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库