mirror of
https://github.com/ratatui/ratatui.git
synced 2025-10-02 15:25:54 +00:00
perf(bench): Used iter_batched
to clone widgets in setup function (#383)
Replaced `Bencher::iter` by `Bencher::iter_batched` to clone the widget in the setup function instead of in the benchmark timing.
This commit is contained in:
parent
8c4a2e0fbf
commit
149d48919d
@ -1,4 +1,4 @@
|
|||||||
use criterion::{criterion_group, criterion_main, Bencher, BenchmarkId, Criterion};
|
use criterion::{criterion_group, criterion_main, BatchSize, Bencher, BenchmarkId, Criterion};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
@ -49,9 +49,15 @@ pub fn block(c: &mut Criterion) {
|
|||||||
/// render the block into a buffer of the given `size`
|
/// render the block into a buffer of the given `size`
|
||||||
fn render(bencher: &mut Bencher, block: &Block, size: &Rect) {
|
fn render(bencher: &mut Bencher, block: &Block, size: &Rect) {
|
||||||
let mut buffer = Buffer::empty(*size);
|
let mut buffer = Buffer::empty(*size);
|
||||||
bencher.iter(|| {
|
// We use `iter_batched` to clone the value in the setup function.
|
||||||
block.clone().render(buffer.area, &mut buffer);
|
// See https://github.com/ratatui-org/ratatui/pull/377.
|
||||||
})
|
bencher.iter_batched(
|
||||||
|
|| block.to_owned(),
|
||||||
|
|bench_block| {
|
||||||
|
bench_block.render(buffer.area, &mut buffer);
|
||||||
|
},
|
||||||
|
BatchSize::SmallInput,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, block);
|
criterion_group!(benches, block);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use criterion::{black_box, criterion_group, criterion_main, Bencher, BenchmarkId, Criterion};
|
use criterion::{
|
||||||
|
black_box, criterion_group, criterion_main, BatchSize, Bencher, BenchmarkId, Criterion,
|
||||||
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
@ -69,9 +71,15 @@ pub fn paragraph(c: &mut Criterion) {
|
|||||||
/// render the paragraph into a buffer with the given width
|
/// render the paragraph into a buffer with the given width
|
||||||
fn render(bencher: &mut Bencher, paragraph: &Paragraph, width: u16) {
|
fn render(bencher: &mut Bencher, paragraph: &Paragraph, width: u16) {
|
||||||
let mut buffer = Buffer::empty(Rect::new(0, 0, width, 50));
|
let mut buffer = Buffer::empty(Rect::new(0, 0, width, 50));
|
||||||
bencher.iter(|| {
|
// We use `iter_batched` to clone the value in the setup function.
|
||||||
paragraph.clone().render(buffer.area, &mut buffer);
|
// See https://github.com/ratatui-org/ratatui/pull/377.
|
||||||
})
|
bencher.iter_batched(
|
||||||
|
|| paragraph.to_owned(),
|
||||||
|
|bench_paragraph| {
|
||||||
|
bench_paragraph.render(buffer.area, &mut buffer);
|
||||||
|
},
|
||||||
|
BatchSize::LargeInput,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a string with the given number of lines filled with nonsense words
|
/// Create a string with the given number of lines filled with nonsense words
|
||||||
|
Loading…
x
Reference in New Issue
Block a user