1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
// Tests that ensure weird (but valid) usage behave as expected.
// Miri cannot discover benchmarks.
#![cfg(not(miri))]
use std::time::Duration;
use divan::{Divan, __private::BENCH_ENTRIES};
#[divan::bench(bytes_count = 0u8, chars_count = 0u16, cycles_count = 0u32, items_count = 0u64)]
fn zero_throughput() {}
#[divan::bench(min_time = Duration::ZERO)]
fn min_min() {}
#[divan::bench(max_time = Duration::MAX)]
fn max_max() {}
#[divan::bench]
fn lifetime<'a>() -> &'a str {
"hello"
}
#[divan::bench]
fn embedded() {
#[divan::bench]
fn inner() {
#[divan::bench]
fn inner() {}
}
}
#[divan::bench]
fn r#raw_ident() {}
#[divan::bench(r#name = "raw name ident")]
fn raw_name_ident() {}
#[divan::bench]
extern "system" fn extern_abi_1() {}
#[divan::bench]
#[allow(improper_ctypes_definitions)]
extern "C" fn extern_abi_2(_: divan::Bencher) {}
#[divan::bench(types = [i32, u8])]
extern "system" fn extern_abi_3<T>() {}
#[divan::bench(r#types = [i32, u8])]
#[allow(improper_ctypes_definitions)]
extern "C" fn extern_abi_4<T>(_: divan::Bencher) {}
#[divan::bench(consts = [0, -1, isize::MAX])]
extern "system" fn extern_abi_5<const N: isize>() {}
#[divan::bench(consts = [0, -1, isize::MAX])]
#[allow(improper_ctypes_definitions)]
extern "C" fn extern_abi_6<const N: isize>(_: divan::Bencher) {}
macro_rules! consts {
() => {
[0, -1, isize::MAX]
};
}
#[divan::bench(consts = consts!())]
fn bench_consts<const N: isize>() {}
#[divan::bench(args = [])]
fn empty_args(_: usize) {}
#[divan::bench(types = [])]
#[allow(dead_code)]
fn empty_types<T>() {}
#[divan::bench(consts = [])]
#[allow(dead_code)]
fn empty_consts<const C: usize>() {}
#[divan::bench(args = [], consts = [])]
#[allow(dead_code)]
fn empty_args_consts<const C: usize>(_: usize) {}
#[divan::bench(types = [], consts = [])]
#[allow(dead_code)]
fn empty_types_consts_1<T, const C: usize>() {}
#[divan::bench(consts = [], types = [])]
#[allow(dead_code)]
fn empty_types_consts_2<T, const C: usize>() {}
#[divan::bench(types = [], consts = [])]
#[allow(dead_code)]
fn empty_types_consts_3<const C: usize, T>() {}
#[divan::bench(consts = [], types = [])]
#[allow(dead_code)]
fn empty_types_consts_4<const C: usize, T>() {}
#[test]
fn test_fn() {
Divan::default().test_benches();
}
// Test that each function appears the expected number of times.
#[test]
fn count() {
let mut inner_count = 0;
for entry in BENCH_ENTRIES.iter() {
if entry.meta.raw_name == "inner" {
inner_count += 1;
}
}
assert_eq!(inner_count, 2);
}
// Test expected `BenchEntry.path` values.
#[test]
fn path() {
for entry in BENCH_ENTRIES.iter() {
// Embedded functions do not contain their parent function's name in
// their `module_path!()`.
if entry.meta.raw_name == "inner" {
assert_eq!(entry.meta.module_path, "weird_usage");
}
// "r#" is removed from raw identifiers.
if entry.meta.raw_name.contains("raw_ident") {
assert_eq!(entry.meta.raw_name, "r#raw_ident");
assert_eq!(entry.meta.display_name, "raw_ident");
}
}
}
|