Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix external state in benchmarking (edit.rs) #1155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions rust/rope/benches/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ fn benchmark_char_insertion_one_line_edit(b: &mut Bencher) {
let mut offset = 100;
b.iter(|| {
text.edit(offset..=offset, "a");
offset += 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it still makes sense to do some loop inside the iter? we can just make it some fixed length.

});
}

Expand All @@ -83,7 +82,16 @@ fn benchmark_paste_into_line(b: &mut Bencher) {
let mut offset = 100;
b.iter(|| {
text.edit(offset..=offset, &insertion);
offset += 150;
});
}

#[bench]
fn benchmark_large_paste_into_line(b: &mut Bencher) {
let mut text = Rope::from(build_short_lines(1_000_000));
let insertion = build_short_lines(50_000);
let mut offset = 25_000;
b.iter(|| {
text.edit(offset..=offset, &insertion);
});
}

Expand All @@ -93,7 +101,6 @@ fn benchmark_insert_newline(b: &mut Bencher) {
let mut offset = 1000;
b.iter(|| {
text.edit(offset..=offset, "\n");
offset += 1001;
});
}

Expand All @@ -106,7 +113,18 @@ fn benchmark_overwrite_into_line(b: &mut Bencher) {
// TODO: if the method runs too quickly, this may generate a fault
// since there's an upper limit to how many times this can run.
text.edit(offset..=offset + 20, &insertion);
offset += 30;
});
}

#[bench]
fn benchmark_large_overwrite_into_line(b: &mut Bencher) {
let mut text = Rope::from(build_short_lines(1_000_000));
let insertion = build_short_lines(50_000);
let mut offset = 25_000;
b.iter(|| {
// TODO: if the method runs too quickly, this may generate a fault
// since there's an upper limit to how many times this can run.
text.edit(offset..=offset + 20, &insertion);
});
}

Expand All @@ -118,7 +136,6 @@ fn benchmark_triangle_concat_inplace(b: &mut Bencher) {
let mut offset = 0;
b.iter(|| {
text.edit(offset..=offset, &insertion);
offset += insertion_len;
});
}

Expand Down