1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-08-28 11:36:17 +03:00

fix dummy backend for benchmark and add insert::long::* benches

Этот коммит содержится в:
rhysd
2023-11-03 23:51:19 +09:00
родитель 069e1351a7
Коммит 06f676014b
3 изменённых файлов: 51 добавлений и 4 удалений

Просмотреть файл

@@ -10,7 +10,7 @@ bench = false
[dependencies]
tui-textarea = { path = "..", features = ["no-backend", "search"] }
ratatui = { version = "0.23.0", default-features = false }
ratatui = { version = ">=0.23.0", default-features = false }
[dev-dependencies]
criterion = "0.5"

Просмотреть файл

@@ -62,6 +62,27 @@ fn random_lorem(repeat: usize) -> usize {
textarea.lines().len()
}
#[inline]
fn append_long_lorem(repeat: usize) -> usize {
let mut textarea = TextArea::default();
let mut term = dummy_terminal();
for _ in 0..repeat {
for line in LOREM {
for c in line.chars() {
textarea.input(Input {
key: Key::Char(c),
ctrl: false,
alt: false,
});
term.draw_textarea(&textarea);
}
}
}
textarea.lines().len()
}
fn append(c: &mut Criterion) {
c.bench_function("insert::append::1_lorem", |b| {
b.iter(|| black_box(append_lorem(1)))
@@ -86,5 +107,17 @@ fn random(c: &mut Criterion) {
});
}
criterion_group!(insert, append, random);
fn long(c: &mut Criterion) {
c.bench_function("insert::long::1_lorem", |b| {
b.iter(|| black_box(append_long_lorem(1)))
});
c.bench_function("insert::long::5_lorem", |b| {
b.iter(|| black_box(append_long_lorem(5)))
});
c.bench_function("insert::long::10_lorem", |b| {
b.iter(|| black_box(append_long_lorem(10)))
});
}
criterion_group!(insert, append, random, long);
criterion_main!(insert);

Просмотреть файл

@@ -1,9 +1,9 @@
// We use empty backend for our benchmark instead of tui::backend::TestBackend to make impact of benchmark from tui-rs
// as small as possible.
use ratatui::backend::Backend;
use ratatui::backend::{Backend, WindowSize};
use ratatui::buffer::Cell;
use ratatui::layout::Rect;
use ratatui::layout::{Rect, Size};
use ratatui::Terminal;
use std::io;
use tui_textarea::TextArea;
@@ -84,6 +84,20 @@ impl Backend for DummyBackend {
})
}
#[inline]
fn window_size(&mut self) -> Result<WindowSize, io::Error> {
Ok(WindowSize {
columns_rows: Size {
width: self.width,
height: self.height,
},
pixels: Size {
width: self.width * 6,
height: self.height * 12,
},
})
}
#[inline]
fn flush(&mut self) -> Result<(), io::Error> {
Ok(())