Skip to content

Commit a53b378

Browse files
committed
add comment change to benchmark
1 parent b615c61 commit a53b378

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

crates/ra_cli/src/analysis_bench.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::{
22
path::{PathBuf, Path},
33
time::Instant,
4+
sync::Arc,
45
};
56

6-
use ra_db::{SourceDatabase, salsa::{Database, Durability}};
7-
use ra_ide_api::{AnalysisHost, Analysis, LineCol, FilePosition};
7+
use ra_db::{SourceDatabase, FileId, salsa::{Database, Durability}};
8+
use ra_ide_api::{AnalysisHost, Analysis, LineCol, FilePosition, AnalysisChange};
89

910
use crate::Result;
1011

@@ -16,7 +17,7 @@ pub(crate) enum Op {
1617
pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
1718
let start = Instant::now();
1819
eprint!("loading: ");
19-
let (host, roots) = ra_batch::load_cargo(path)?;
20+
let (mut host, roots) = ra_batch::load_cargo(path)?;
2021
let db = host.raw_database();
2122
eprintln!("{:?}\n", start.elapsed());
2223

@@ -44,7 +45,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
4445

4546
match op {
4647
Op::Highlight { .. } => {
47-
let res = do_work(&host, |analysis| {
48+
let res = do_work(&mut host, file_id, |analysis| {
4849
analysis.diagnostics(file_id).unwrap();
4950
analysis.highlight_as_html(file_id, false).unwrap()
5051
});
@@ -59,7 +60,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
5960
.offset(LineCol { line, col_utf16: column });
6061
let file_postion = FilePosition { file_id, offset };
6162

62-
let res = do_work(&host, |analysis| analysis.completions(file_postion));
63+
let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
6364
if verbose {
6465
println!("\n{:#?}", res);
6566
}
@@ -68,7 +69,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
6869
Ok(())
6970
}
7071

71-
fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T {
72+
fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, work: F) -> T {
7273
{
7374
let start = Instant::now();
7475
eprint!("from scratch: ");
@@ -88,6 +89,19 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T {
8889
work(&host.analysis());
8990
eprintln!("{:?}", start.elapsed());
9091
}
92+
{
93+
let start = Instant::now();
94+
eprint!("comment change: ");
95+
{
96+
let mut text = host.analysis().file_text(file_id).to_string();
97+
text.push_str("\n/* Hello world */\n");
98+
let mut change = AnalysisChange::new();
99+
change.change_file(file_id, Arc::new(text));
100+
host.apply_change(change);
101+
}
102+
work(&host.analysis());
103+
eprintln!("{:?}", start.elapsed());
104+
}
91105
{
92106
let start = Instant::now();
93107
eprint!("const change: ");

0 commit comments

Comments
 (0)