nvzqz / divan

Fast and simple benchmarking for Rust projects

Home Page:https://nikolaivazquez.com/blog/divan/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Differentiate provided generic types on name collision

nvzqz opened this issue · comments

The following code:

struct String;

#[divan::bench(types = [String, std::string::String])]
fn bench<T>() {}

...produces this output tree structure:

example
╰─ bench
   ├─ String
   ╰─ String

This makes it very difficult to differentiate which String is being referred to. It's not impossible because the sorting is based on input order if names collide.

This is also quite frustrating when unqualified names are the same and constants are used.

use divan::{Bencher, black_box};

fn main() { divan::main(); }

mod A { pub struct Foo; }
mod B { pub struct Foo; }

#[divan::bench(types = [A::Foo, B::Foo], consts = [1,2])]
fn foos<T, const N: usize>(bencher: Bencher) {
    bencher.bench(|| () );
}

Results in:

Timer precision: 15 ns
example     fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ foos                   │               │               │               │         │
   ╰─ Foo                 │               │               │               │         │
      ├─ 1  0.112 ns      │ 0.265 ns      │ 0.114 ns      │ 0.117 ns      │ 100     │ 819200
      ├─ 1  0.112 ns      │ 0.126 ns      │ 0.113 ns      │ 0.115 ns      │ 100     │ 819200
      ├─ 2  0.112 ns      │ 0.114 ns      │ 0.113 ns      │ 0.113 ns      │ 100     │ 819200
      ╰─ 2  0.107 ns      │ 0.262 ns      │ 0.113 ns      │ 0.116 ns      │ 100     │ 819200

When really it should disambiguate as:

Timer precision: 15 ns
example     fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ foos                   │               │               │               │         │
   ├─ A::Foo              │               │               │               │         │
   │  ├─ 1  0.126 ns      │ 0.134 ns      │ 0.127 ns      │ 0.128 ns      │ 100     │ 819200
   │  ╰─ 2  0.121 ns      │ 0.129 ns      │ 0.121 ns      │ 0.122 ns      │ 100     │ 819200
   ╰─ B::Foo              │               │               │               │         │
      ├─ 1  0.121 ns      │ 0.826 ns      │ 0.121 ns      │ 0.134 ns      │ 100     │ 819200
      ╰─ 2  0.121 ns      │ 0.124 ns      │ 0.121 ns      │ 0.121 ns      │ 100     │ 819200