Skip to content

Commit 8fb26f9

Browse files
committed
Add "Count" suffix to known counters
1 parent bb92538 commit 8fb26f9

File tree

9 files changed

+73
-73
lines changed

9 files changed

+73
-73
lines changed

examples/benches/image.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Benchmarks the [`image`](https://docs.rs/image) crate.
22
3-
use divan::{black_box, counter::Bytes, Bencher};
3+
use divan::{black_box, counter::BytesCount, Bencher};
44
use image::{GenericImage, ImageBuffer, Rgba};
55

66
fn main() {
@@ -18,7 +18,7 @@ fn copy_from(bencher: Bencher) {
1818
let mut dst = make_image(Rgba([0u8, 0, 0, 255]));
1919

2020
bencher
21-
.counter(Bytes::of_slice(&*src))
21+
.counter(BytesCount::of_slice(&*src))
2222
.bench(|| black_box(&mut dst).copy_from(black_box(&src), 0, 0));
2323
}
2424

@@ -29,6 +29,6 @@ fn memcpy(bencher: Bencher) {
2929
let mut dst = vec![0; src.len()];
3030

3131
bencher
32-
.counter(Bytes::of_slice(&*src))
32+
.counter(BytesCount::of_slice(&*src))
3333
.bench(|| black_box(&mut dst).copy_from_slice(black_box(&src)));
3434
}

examples/benches/string.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use divan::{
22
black_box,
3-
counter::{Bytes, Chars},
3+
counter::{BytesCount, CharsCount},
44
Bencher,
55
};
66

@@ -44,9 +44,9 @@ impl GenString for Unicode {
4444
fn clear<G: GenString, const N: usize>(bencher: Bencher) {
4545
let mut gen = G::default();
4646
bencher
47-
.counter(Chars::new(N))
47+
.counter(CharsCount::new(N))
4848
.with_inputs(|| gen.gen_string(N))
49-
.input_counter(Bytes::of_str)
49+
.input_counter(BytesCount::of_str)
5050
.bench_local_refs(String::clear);
5151
}
5252

@@ -57,9 +57,9 @@ fn clear<G: GenString, const N: usize>(bencher: Bencher) {
5757
fn drop<G: GenString, const N: usize>(bencher: Bencher) {
5858
let mut gen = G::default();
5959
bencher
60-
.counter(Chars::new(N))
60+
.counter(CharsCount::new(N))
6161
.with_inputs(|| gen.gen_string(N))
62-
.input_counter(Bytes::of_str)
62+
.input_counter(BytesCount::of_str)
6363
.bench_local_values(std::mem::drop);
6464
}
6565

@@ -70,9 +70,9 @@ fn drop<G: GenString, const N: usize>(bencher: Bencher) {
7070
fn validate_utf8<G: GenString, const N: usize>(bencher: Bencher) {
7171
let mut gen = G::default();
7272
bencher
73-
.counter(Chars::new(N))
73+
.counter(CharsCount::new(N))
7474
.with_inputs(|| gen.gen_string(N))
75-
.input_counter(Bytes::of_str)
75+
.input_counter(BytesCount::of_str)
7676
.bench_local_refs(|s| {
7777
let bytes = black_box(s.as_bytes());
7878
_ = black_box(std::str::from_utf8(bytes));
@@ -86,9 +86,9 @@ fn validate_utf8<G: GenString, const N: usize>(bencher: Bencher) {
8686
fn char_count<G: GenString, const N: usize>(bencher: Bencher) {
8787
let mut gen = G::default();
8888
bencher
89-
.counter(Chars::new(N))
89+
.counter(CharsCount::new(N))
9090
.with_inputs(|| gen.gen_string(N))
91-
.input_counter(Bytes::of_str)
91+
.input_counter(BytesCount::of_str)
9292
.bench_local_refs(|s| s.chars().count());
9393
}
9494

@@ -99,9 +99,9 @@ fn char_count<G: GenString, const N: usize>(bencher: Bencher) {
9999
fn make_ascii_lowercase<G: GenString, const N: usize>(bencher: Bencher) {
100100
let mut gen = G::default();
101101
bencher
102-
.counter(Chars::new(N))
102+
.counter(CharsCount::new(N))
103103
.with_inputs(|| gen.gen_string(N))
104-
.input_counter(Bytes::of_str)
104+
.input_counter(BytesCount::of_str)
105105
.bench_local_refs(|s| s.make_ascii_lowercase());
106106
}
107107

@@ -112,9 +112,9 @@ fn make_ascii_lowercase<G: GenString, const N: usize>(bencher: Bencher) {
112112
fn make_ascii_uppercase<G: GenString, const N: usize>(bencher: Bencher) {
113113
let mut gen = G::default();
114114
bencher
115-
.counter(Chars::new(N))
115+
.counter(CharsCount::new(N))
116116
.with_inputs(|| gen.gen_string(N))
117-
.input_counter(Bytes::of_str)
117+
.input_counter(BytesCount::of_str)
118118
.bench_local_refs(|s| s.make_ascii_uppercase());
119119
}
120120

@@ -125,9 +125,9 @@ fn make_ascii_uppercase<G: GenString, const N: usize>(bencher: Bencher) {
125125
fn to_ascii_lowercase<G: GenString, const N: usize>(bencher: Bencher) {
126126
let mut gen = G::default();
127127
bencher
128-
.counter(Chars::new(N))
128+
.counter(CharsCount::new(N))
129129
.with_inputs(|| gen.gen_string(N))
130-
.input_counter(Bytes::of_str)
130+
.input_counter(BytesCount::of_str)
131131
.bench_local_refs(|s| s.to_ascii_lowercase());
132132
}
133133

@@ -138,9 +138,9 @@ fn to_ascii_lowercase<G: GenString, const N: usize>(bencher: Bencher) {
138138
fn to_ascii_uppercase<G: GenString, const N: usize>(bencher: Bencher) {
139139
let mut gen = G::default();
140140
bencher
141-
.counter(Chars::new(N))
141+
.counter(CharsCount::new(N))
142142
.with_inputs(|| gen.gen_string(N))
143-
.input_counter(Bytes::of_str)
143+
.input_counter(BytesCount::of_str)
144144
.bench_local_refs(|s| s.to_ascii_uppercase());
145145
}
146146

@@ -151,9 +151,9 @@ fn to_ascii_uppercase<G: GenString, const N: usize>(bencher: Bencher) {
151151
fn to_lowercase<G: GenString, const N: usize>(bencher: Bencher) {
152152
let mut gen = G::default();
153153
bencher
154-
.counter(Chars::new(N))
154+
.counter(CharsCount::new(N))
155155
.with_inputs(|| gen.gen_string(N))
156-
.input_counter(Bytes::of_str)
156+
.input_counter(BytesCount::of_str)
157157
.bench_local_refs(|s| s.to_lowercase());
158158
}
159159

@@ -164,8 +164,8 @@ fn to_lowercase<G: GenString, const N: usize>(bencher: Bencher) {
164164
fn to_uppercase<G: GenString, const N: usize>(bencher: Bencher) {
165165
let mut gen = G::default();
166166
bencher
167-
.counter(Chars::new(N))
167+
.counter(CharsCount::new(N))
168168
.with_inputs(|| gen.gen_string(N))
169-
.input_counter(Bytes::of_str)
169+
.input_counter(BytesCount::of_str)
170170
.bench_local_refs(|s| s.to_uppercase());
171171
}

src/bench/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818

1919
// Used for intra-doc links.
2020
#[allow(unused)]
21-
use crate::counter::Bytes;
21+
use crate::counter::BytesCount;
2222

2323
#[cfg(test)]
2424
mod tests;
@@ -169,15 +169,15 @@ impl<'a, 'b, GenI> Bencher<'a, 'b, BencherConfig<GenI>> {
169169
/// # Examples
170170
///
171171
/// ```
172-
/// use divan::{Bencher, counter::Bytes};
172+
/// use divan::{Bencher, counter::BytesCount};
173173
///
174174
/// #[divan::bench]
175175
/// fn char_count(bencher: Bencher) {
176176
/// let s: String = // ...
177177
/// # String::new();
178178
///
179179
/// bencher
180-
/// .counter(Bytes::of_str(&s))
180+
/// .counter(BytesCount::of_str(&s))
181181
/// .bench(|| {
182182
/// divan::black_box(&s).chars().count()
183183
/// });
@@ -216,11 +216,11 @@ where
216216
///
217217
/// The following example emits info for the number of bytes processed when
218218
/// benchmarking [`char`-counting](std::str::Chars::count). The byte count
219-
/// is gotten by calling [`Bytes::of_str`] on each iteration's input
219+
/// is gotten by calling [`BytesCount::of_str`] on each iteration's input
220220
/// [`String`].
221221
///
222222
/// ```
223-
/// use divan::{Bencher, counter::Bytes};
223+
/// use divan::{Bencher, counter::BytesCount};
224224
///
225225
/// #[divan::bench]
226226
/// fn char_count(bencher: Bencher) {
@@ -229,7 +229,7 @@ where
229229
/// // ...
230230
/// # String::new()
231231
/// })
232-
/// .input_counter(Bytes::of_str)
232+
/// .input_counter(BytesCount::of_str)
233233
/// .bench_refs(|s| {
234234
/// s.chars().count()
235235
/// });

src/counter/any_counter.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{any::TypeId, fmt};
22

33
use crate::{
4-
counter::{Bytes, BytesFormat, Chars, IntoCounter, Items, MaxCountUInt},
4+
counter::{BytesCount, BytesFormat, CharsCount, IntoCounter, ItemsCount, MaxCountUInt},
55
time::FineDuration,
66
util,
77
};
@@ -21,11 +21,11 @@ impl AnyCounter {
2121
pub(crate) fn new<C: IntoCounter>(counter: C) -> Self {
2222
let counter = counter.into_counter();
2323

24-
if let Some(bytes) = util::cast_ref::<Bytes>(&counter) {
24+
if let Some(bytes) = util::cast_ref::<BytesCount>(&counter) {
2525
Self::bytes(bytes.count)
26-
} else if let Some(chars) = util::cast_ref::<Chars>(&counter) {
26+
} else if let Some(chars) = util::cast_ref::<CharsCount>(&counter) {
2727
Self::chars(chars.count)
28-
} else if let Some(items) = util::cast_ref::<Items>(&counter) {
28+
} else if let Some(items) = util::cast_ref::<ItemsCount>(&counter) {
2929
Self::items(items.count)
3030
} else {
3131
unreachable!()
@@ -90,11 +90,11 @@ impl KnownCounterKind {
9090
#[inline]
9191
pub fn of<C: IntoCounter>() -> Self {
9292
let id = TypeId::of::<C::Counter>();
93-
if id == TypeId::of::<Bytes>() {
93+
if id == TypeId::of::<BytesCount>() {
9494
Self::Bytes
95-
} else if id == TypeId::of::<Chars>() {
95+
} else if id == TypeId::of::<CharsCount>() {
9696
Self::Chars
97-
} else if id == TypeId::of::<Items>() {
97+
} else if id == TypeId::of::<ItemsCount>() {
9898
Self::Items
9999
} else {
100100
unreachable!()

src/counter/into_counter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::counter::Counter;
44
///
55
/// # Examples
66
///
7-
/// This trait is implemented for unsigned integers over the
8-
/// [`Items`](crate::counter::Items) counter:
7+
/// This trait is implemented for unsigned integers over
8+
/// [`ItemsCount`](crate::counter::ItemsCount):
99
///
1010
/// ```
1111
/// #[divan::bench]

src/counter/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
//! # Examples
44
//!
55
//! The following example measures throughput of converting
6-
//! [`&[i32]`](prim@slice) into [`Vec<i32>`](Vec) by providing [`Bytes`] via
6+
//! [`&[i32]`](prim@slice) into [`Vec<i32>`](Vec) by providing [`BytesCount`] via
77
//! [`Bencher::counter`](crate::Bencher::counter):
88
//!
99
//! ```
10-
//! use divan::counter::Bytes;
10+
//! use divan::counter::BytesCount;
1111
//!
1212
//! #[divan::bench]
1313
//! fn slice_into_vec(bencher: divan::Bencher) {
1414
//! let ints: &[i32] = &[
1515
//! // ...
1616
//! ];
1717
//!
18-
//! let bytes = Bytes::of_slice(ints);
18+
//! let bytes = BytesCount::of_slice(ints);
1919
//!
2020
//! bencher
2121
//! .counter(bytes)
@@ -54,7 +54,7 @@ pub trait Counter: Sized + Any + Sealed {}
5454

5555
/// Process N bytes.
5656
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
57-
pub struct Bytes {
57+
pub struct BytesCount {
5858
count: MaxCountUInt,
5959
}
6060

@@ -64,25 +64,25 @@ pub struct Bytes {
6464
/// implementations, since the number of code points is a common baseline
6565
/// reference.
6666
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
67-
pub struct Chars {
67+
pub struct CharsCount {
6868
count: MaxCountUInt,
6969
}
7070

7171
/// Process N items.
7272
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
73-
pub struct Items {
73+
pub struct ItemsCount {
7474
count: MaxCountUInt,
7575
}
7676

77-
impl Sealed for Bytes {}
78-
impl Sealed for Chars {}
79-
impl Sealed for Items {}
77+
impl Sealed for BytesCount {}
78+
impl Sealed for CharsCount {}
79+
impl Sealed for ItemsCount {}
8080

81-
impl Counter for Bytes {}
82-
impl Counter for Chars {}
83-
impl Counter for Items {}
81+
impl Counter for BytesCount {}
82+
impl Counter for CharsCount {}
83+
impl Counter for ItemsCount {}
8484

85-
impl Bytes {
85+
impl BytesCount {
8686
/// Count N bytes.
8787
#[inline]
8888
pub fn new<N: CountUInt>(count: N) -> Self {
@@ -106,7 +106,7 @@ impl Bytes {
106106

107107
/// Counts the bytes of a [`&str`].
108108
///
109-
/// This is like [`Bytes::of_val`] with the convenience of behaving as
109+
/// This is like [`BytesCount::of_val`] with the convenience of behaving as
110110
/// expected for [`&String`](String) and other types that convert to
111111
/// [`&str`].
112112
///
@@ -118,7 +118,7 @@ impl Bytes {
118118

119119
/// Counts the bytes of a [slice](prim@slice).
120120
///
121-
/// This is like [`Bytes::of_val`] with the convenience of behaving as
121+
/// This is like [`BytesCount::of_val`] with the convenience of behaving as
122122
/// expected for [`&Vec<T>`](Vec) and other types that convert to
123123
/// [`&[T]`](prim@slice).
124124
#[inline]
@@ -127,7 +127,7 @@ impl Bytes {
127127
}
128128
}
129129

130-
impl Chars {
130+
impl CharsCount {
131131
/// Count N [`char`s](char).
132132
#[inline]
133133
pub fn new<N: CountUInt>(count: N) -> Self {
@@ -141,15 +141,15 @@ impl Chars {
141141
}
142142
}
143143

144-
impl Items {
144+
impl ItemsCount {
145145
/// Count N items.
146146
#[inline]
147147
pub fn new<N: CountUInt>(count: N) -> Self {
148148
Self { count: count.into_max_uint() }
149149
}
150150
}
151151

152-
/// The numerical base for [`Bytes`] in benchmark outputs.
152+
/// The numerical base for [`BytesCount`] in benchmark outputs.
153153
///
154154
/// See [`Divan::bytes_format`](crate::Divan::bytes_format) for more info.
155155
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]

src/counter/uint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::any::Any;
22

3-
use crate::counter::{IntoCounter, Items};
3+
use crate::counter::{IntoCounter, ItemsCount};
44

55
/// The largest unsigned integer usable by counters provided by this crate.
66
///
@@ -29,11 +29,11 @@ macro_rules! impl_uint {
2929
})+
3030

3131
$(impl IntoCounter for $i {
32-
type Counter = Items;
32+
type Counter = ItemsCount;
3333

3434
#[inline]
35-
fn into_counter(self) -> Items {
36-
Items::new(self)
35+
fn into_counter(self) -> ItemsCount {
36+
ItemsCount::new(self)
3737
}
3838
})+
3939
};

src/divan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ impl Divan {
452452
self
453453
}
454454

455-
/// Determines how [`Bytes`](crate::counter::Bytes) is scaled in benchmark
456-
/// outputs.
455+
/// Determines how [`BytesCount`](crate::counter::BytesCount) is scaled in
456+
/// benchmark outputs.
457457
///
458458
/// This option is equivalent to the `--bytes-format` CLI argument.
459459
#[inline]

0 commit comments

Comments
 (0)