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

Add more benchmarks #1152

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.

24 changes: 24 additions & 0 deletions rust/rope/benches/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ fn benchmark_paste_into_line(b: &mut Bencher) {
});
}

#[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);
offset += 150;
Copy link
Member

Choose a reason for hiding this comment

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

Reading this is making me wonder if a bunch of these benchmarks (the existing ones) aren't poorly structured.

Specifically, everything in b.iter(|| { should be identical between each run, but we're regularly changing external state. This means that different runs are running different code, which sort of defeats the purpose of benchmarking.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch. I removed my review. @kanishkarj do you think we can have a PR fixing the outlined issue from @cmyr, this means removing the change of state (e.g. offset += 150) in the iteration? We should fix this for the edit.rs benchmark cases and then rebase your PR on top of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider it done. :)

});
}

#[bench]
fn benchmark_insert_newline(b: &mut Bencher) {
let mut text = Rope::from(build_few_big_lines(1_000_000));
Expand All @@ -110,6 +121,19 @@ fn benchmark_overwrite_into_line(b: &mut Bencher) {
});
}

#[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);
offset += 30;
});
}

#[bench]
fn benchmark_triangle_concat_inplace(b: &mut Bencher) {
let mut text = Rope::from("");
Expand Down