mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-09 12:16:43 +03:00
added insert_char benchmark
This commit is contained in:
parent
59509748b5
commit
55cd6a4976
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2659,6 +2659,7 @@ dependencies = [
|
||||
"bytemuck",
|
||||
"cgmath",
|
||||
"colored",
|
||||
"criterion",
|
||||
"env_logger 0.7.1",
|
||||
"futures",
|
||||
"glyph_brush",
|
||||
|
@ -34,3 +34,6 @@ members = [
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
debug = true # enable when profiling
|
||||
|
||||
|
||||
|
@ -81,6 +81,11 @@ maplit = "1.0.1"
|
||||
indoc = "0.3.3"
|
||||
quickcheck = "0.8"
|
||||
quickcheck_macros = "0.8"
|
||||
criterion = "0.3"
|
||||
|
||||
[[bench]]
|
||||
name = "my_benchmark"
|
||||
harness = false
|
||||
|
||||
# uncomment everything below if you have made changes to any shaders and
|
||||
# want to compile them to .spv
|
||||
|
52
editor/benches/my_benchmark.rs
Normal file
52
editor/benches/my_benchmark.rs
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use roc_editor::mvc::update::handle_new_char;
|
||||
use roc_editor::mvc::ed_model::{EdModel, Position, RawSelection};
|
||||
use roc_editor::mvc::app_model::AppModel;
|
||||
use roc_editor::text_buffer::TextBuffer;
|
||||
use ropey::Rope;
|
||||
|
||||
// duplicate inside mvc::update
|
||||
fn mock_app_model(
|
||||
text_buf: TextBuffer,
|
||||
caret_pos: Position,
|
||||
selection_opt: Option<RawSelection>,
|
||||
) -> AppModel {
|
||||
AppModel {
|
||||
ed_model_opt: Some(EdModel {
|
||||
text_buf,
|
||||
caret_pos,
|
||||
selection_opt,
|
||||
glyph_dim_rect_opt: None,
|
||||
has_focus: true,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn text_buffer_from_str(lines_str: &str) -> TextBuffer {
|
||||
TextBuffer {
|
||||
text_rope: Rope::from_str(lines_str),
|
||||
path_str: "".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn char_insert_benchmark(c: &mut Criterion) {
|
||||
let text_buf = text_buffer_from_str("");
|
||||
|
||||
let caret_pos = Position {
|
||||
line: 0,
|
||||
column: 0
|
||||
};
|
||||
|
||||
let selection_opt: Option<RawSelection> = None;
|
||||
let mut app_model = mock_app_model(text_buf, caret_pos, selection_opt);
|
||||
c.bench_function("single char insert, small buffer", |b| b.iter(|| handle_new_char(&mut app_model, &'a')));
|
||||
}
|
||||
|
||||
pub fn file_open_benchmark(c: &mut Criterion) {
|
||||
ed_model::init_model(path)
|
||||
//TODO continue here
|
||||
}
|
||||
|
||||
criterion_group!(benches, char_insert_benchmark);
|
||||
criterion_main!(benches);
|
@ -46,10 +46,12 @@ pub mod error;
|
||||
pub mod graphics;
|
||||
mod keyboard_input;
|
||||
pub mod lang;
|
||||
mod mvc;
|
||||
//mod mvc;
|
||||
pub mod mvc; // for benchmarking
|
||||
mod resources;
|
||||
mod selection;
|
||||
mod text_buffer;
|
||||
//mod text_buffer;
|
||||
pub mod text_buffer; // for benchmarking
|
||||
mod util;
|
||||
mod vec_result;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user