aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src/analysis_bench.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src/analysis_bench.rs')
-rw-r--r--crates/ra_cli/src/analysis_bench.rs127
1 files changed, 0 insertions, 127 deletions
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs
deleted file mode 100644
index 91fc55fe2..000000000
--- a/crates/ra_cli/src/analysis_bench.rs
+++ /dev/null
@@ -1,127 +0,0 @@
1//! FIXME: write short doc here
2
3use std::{path::Path, sync::Arc, time::Instant};
4
5use anyhow::format_err;
6use ra_db::{
7 salsa::{Database, Durability},
8 FileId, SourceDatabaseExt,
9};
10use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
11
12use crate::{load_cargo::load_cargo, BenchWhat, Result, Verbosity};
13
14pub(crate) fn run(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<()> {
15 ra_prof::init();
16
17 let start = Instant::now();
18 eprint!("loading: ");
19 let (mut host, roots) = load_cargo(path)?;
20 let db = host.raw_database();
21 eprintln!("{:?}\n", start.elapsed());
22
23 let file_id = {
24 let path = match &what {
25 BenchWhat::Highlight { path } => path,
26 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => &pos.path,
27 };
28 let path = std::env::current_dir()?.join(path).canonicalize()?;
29 roots
30 .iter()
31 .find_map(|(source_root_id, project_root)| {
32 if project_root.is_member() {
33 for file_id in db.source_root(*source_root_id).walk() {
34 let rel_path = db.file_relative_path(file_id);
35 let abs_path = rel_path.to_path(project_root.path());
36 if abs_path == path {
37 return Some(file_id);
38 }
39 }
40 }
41 None
42 })
43 .ok_or_else(|| format_err!("Can't find {}", path.display()))?
44 };
45
46 match &what {
47 BenchWhat::Highlight { .. } => {
48 let res = do_work(&mut host, file_id, |analysis| {
49 analysis.diagnostics(file_id).unwrap();
50 analysis.highlight_as_html(file_id, false).unwrap()
51 });
52 if verbosity.is_verbose() {
53 println!("\n{}", res);
54 }
55 }
56 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => {
57 let is_completion = match what {
58 BenchWhat::Complete(..) => true,
59 _ => false,
60 };
61
62 let offset = host
63 .analysis()
64 .file_line_index(file_id)?
65 .offset(LineCol { line: pos.line - 1, col_utf16: pos.column });
66 let file_postion = FilePosition { file_id, offset };
67
68 if is_completion {
69 let res =
70 do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
71 if verbosity.is_verbose() {
72 println!("\n{:#?}", res);
73 }
74 } else {
75 let res =
76 do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_postion));
77 if verbosity.is_verbose() {
78 println!("\n{:#?}", res);
79 }
80 }
81 }
82 }
83 Ok(())
84}
85
86fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, work: F) -> T {
87 {
88 let start = Instant::now();
89 eprint!("from scratch: ");
90 work(&host.analysis());
91 eprintln!("{:?}", start.elapsed());
92 }
93 {
94 let start = Instant::now();
95 eprint!("no change: ");
96 work(&host.analysis());
97 eprintln!("{:?}", start.elapsed());
98 }
99 {
100 let start = Instant::now();
101 eprint!("trivial change: ");
102 host.raw_database_mut().salsa_runtime_mut().synthetic_write(Durability::LOW);
103 work(&host.analysis());
104 eprintln!("{:?}", start.elapsed());
105 }
106 {
107 let start = Instant::now();
108 eprint!("comment change: ");
109 {
110 let mut text = host.analysis().file_text(file_id).unwrap().to_string();
111 text.push_str("\n/* Hello world */\n");
112 let mut change = AnalysisChange::new();
113 change.change_file(file_id, Arc::new(text));
114 host.apply_change(change);
115 }
116 work(&host.analysis());
117 eprintln!("{:?}", start.elapsed());
118 }
119 {
120 let start = Instant::now();
121 eprint!("const change: ");
122 host.raw_database_mut().salsa_runtime_mut().synthetic_write(Durability::HIGH);
123 let res = work(&host.analysis());
124 eprintln!("{:?}", start.elapsed());
125 res
126 }
127}