make criterion args work, small simplification

This commit is contained in:
Bernardo 2018-12-22 22:11:10 +01:00
parent dc2afae991
commit c886b72dab
3 changed files with 18 additions and 18 deletions

View file

@ -23,6 +23,10 @@ rand = "*"
rand_xorshift = "*" rand_xorshift = "*"
lazy_static = "*" lazy_static = "*"
[lib]
# so that criterion arguments work, see: https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
bench = false
[[bench]] [[bench]]
name = "translate_offset_with_edit_benchmark" name = "translate_offset_with_edit_benchmark"
harness = false harness = false

View file

@ -65,21 +65,20 @@ lazy_static! {
} }
fn compare_translates(c: &mut Criterion) { fn compare_translates(c: &mut Criterion) {
let f1 = Fun::new("translate_after_edit", |b, _| { let functions = vec![
b.iter(|| { Fun::new("translate_after_edit", |b, _| {
let d = &*DATA; b.iter(|| {
line_index_utils::translate_after_edit(&d.text, d.offset, d.edits.clone()); let d = &*DATA;
}) line_index_utils::translate_after_edit(&d.text, d.offset, d.edits.clone());
}); })
}),
let f2 = Fun::new("translate_offset_with_edit", |b, _| { Fun::new("translate_offset_with_edit", |b, _| {
b.iter(|| { b.iter(|| {
let d = &*DATA; let d = &*DATA;
line_index_utils::translate_offset_with_edit(&d.line_index, d.offset, &d.edits); line_index_utils::translate_offset_with_edit(&d.line_index, d.offset, &d.edits);
}) })
}); }),
];
let functions = vec![f1, f2];
c.bench_functions("translate", functions, ()); c.bench_functions("translate", functions, ());
} }

View file

@ -270,9 +270,6 @@ pub fn translate_offset_with_edit(
Step::Newline(n) => { Step::Newline(n) => {
if offset < *n { if offset < *n {
return res.to_line_col(offset); return res.to_line_col(offset);
} else if offset == *n {
res.add_line(*n);
return res.to_line_col(offset);
} else { } else {
res.add_line(*n); res.add_line(*n);
} }