diff --git a/Cargo.lock b/Cargo.lock index 90c3bdc7bb..d2f1756c6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2659,6 +2659,7 @@ dependencies = [ "bytemuck", "cgmath", "colored", + "criterion", "env_logger 0.7.1", "futures", "glyph_brush", diff --git a/Cargo.toml b/Cargo.toml index 5b4fe8cf10..777e51cf01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,3 +34,6 @@ members = [ [profile.release] lto = "fat" codegen-units = 1 +debug = true # enable when profiling + + diff --git a/editor/Cargo.toml b/editor/Cargo.toml index 61aec5ade5..fd79dd0fb8 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -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 diff --git a/editor/benches/my_benchmark.rs b/editor/benches/my_benchmark.rs new file mode 100644 index 0000000000..69a0cc53a3 --- /dev/null +++ b/editor/benches/my_benchmark.rs @@ -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, +) -> 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 = 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); diff --git a/editor/src/lib.rs b/editor/src/lib.rs index a04d5aa65d..cfdf2c6eb2 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -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;