зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 16:35:49 +03:00
fix dummy backend for benchmark and add insert::long::* benches
Этот коммит содержится в:
@@ -10,7 +10,7 @@ bench = false
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tui-textarea = { path = "..", features = ["no-backend", "search"] }
|
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]
|
[dev-dependencies]
|
||||||
criterion = "0.5"
|
criterion = "0.5"
|
||||||
|
|||||||
@@ -62,6 +62,27 @@ fn random_lorem(repeat: usize) -> usize {
|
|||||||
textarea.lines().len()
|
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) {
|
fn append(c: &mut Criterion) {
|
||||||
c.bench_function("insert::append::1_lorem", |b| {
|
c.bench_function("insert::append::1_lorem", |b| {
|
||||||
b.iter(|| black_box(append_lorem(1)))
|
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);
|
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
|
// We use empty backend for our benchmark instead of tui::backend::TestBackend to make impact of benchmark from tui-rs
|
||||||
// as small as possible.
|
// as small as possible.
|
||||||
|
|
||||||
use ratatui::backend::Backend;
|
use ratatui::backend::{Backend, WindowSize};
|
||||||
use ratatui::buffer::Cell;
|
use ratatui::buffer::Cell;
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::{Rect, Size};
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use std::io;
|
use std::io;
|
||||||
use tui_textarea::TextArea;
|
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]
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<(), io::Error> {
|
fn flush(&mut self) -> Result<(), io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user