Skip to content

Commit

Permalink
Fix benches to use std ToString
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Dec 6, 2024
1 parent 4230fc1 commit eb58277
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 9 additions & 10 deletions utils/writeable/benches/writeable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,23 @@ fn writeable_dyn_benches(c: &mut Criterion) {
fn display_benches(c: &mut Criterion) {
c.bench_function("display/to_string/short", |b| {
b.iter(|| {
DisplayMessage {
std::string::ToString::to_string(&DisplayMessage {
message: black_box(SHORT_STR),
}
.to_string()
})
});
});
c.bench_function("display/to_string/medium", |b| {
b.iter(|| {
DisplayMessage {
std::string::ToString::to_string(&DisplayMessage {
message: black_box(MEDIUM_STR),
}
.to_string()
})
});
});
c.bench_function("display/to_string/long", |b| {
b.iter(|| {
DisplayMessage {
std::string::ToString::to_string(&DisplayMessage {
message: black_box(LONG_STR),
}
.to_string()
})
});
});
c.bench_function("display/fmt/short", |b| {
Expand Down Expand Up @@ -282,7 +279,9 @@ fn complex_benches(c: &mut Criterion) {
});
});
c.bench_function("complex/display_to_string/medium", |b| {
b.iter(|| black_box(COMPLEX_WRITEABLE_MEDIUM).to_string());
b.iter(|| {
std::string::ToString::to_string(&black_box(COMPLEX_WRITEABLE_MEDIUM))
});
});
const REFERENCE_STRS: [&str; 6] = [
"There are 55 apples and 8124 oranges",
Expand Down
6 changes: 3 additions & 3 deletions utils/writeable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
//!
//! | Case | `Writeable` | `Display` |
//! |---|---|---|
//! | Create string from single-string message (139 chars) | 19.999 ns | 22.133 ns |
//! | Create string from complex message | 35.838 ns | 87.703 ns |
//! | Write complex message to buffer | 56.855 ns | 64.971 ns |
//! | Create string from single-string message (139 chars) | 15.642 ns | 19.251 ns |
//! | Create string from complex message | 35.830 ns | 89.478 ns |
//! | Write complex message to buffer | 57.336 ns | 64.408 ns |
//!
//! # Examples
//!
Expand Down

0 comments on commit eb58277

Please sign in to comment.