summaryrefslogtreecommitdiff
path: root/cli/bench
diff options
context:
space:
mode:
Diffstat (limited to 'cli/bench')
-rw-r--r--cli/bench/lsp.rs42
-rw-r--r--cli/bench/lsp_bench_standalone.rs15
2 files changed, 12 insertions, 45 deletions
diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs
index 722a87b69..b0682e2e9 100644
--- a/cli/bench/lsp.rs
+++ b/cli/bench/lsp.rs
@@ -9,15 +9,13 @@ use deno_core::url::Url;
use std::collections::HashMap;
use std::path::Path;
use std::time::Duration;
-use test_util::lsp::LspClient;
+use test_util::lsp::LspClientBuilder;
use test_util::lsp::LspResponseError;
use tower_lsp::lsp_types as lsp;
static FIXTURE_CODE_LENS_TS: &str = include_str!("testdata/code_lens.ts");
static FIXTURE_DB_TS: &str = include_str!("testdata/db.ts");
static FIXTURE_DB_MESSAGES: &[u8] = include_bytes!("testdata/db_messages.json");
-static FIXTURE_INIT_JSON: &[u8] =
- include_bytes!("testdata/initialize_params.json");
#[derive(Debug, Deserialize)]
enum FixtureType {
@@ -44,14 +42,8 @@ struct FixtureMessage {
/// the end of the document and does a level of hovering and gets quick fix
/// code actions.
fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
- let mut client = LspClient::new(deno_exe, false)?;
-
- let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
- let (_, response_error): (Option<Value>, Option<LspResponseError>) =
- client.write_request("initialize", params)?;
- assert!(response_error.is_none());
-
- client.write_notification("initialized", json!({}))?;
+ let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
+ client.initialize_default();
client.write_notification(
"textDocument/didOpen",
@@ -125,13 +117,8 @@ fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
}
fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
- let mut client = LspClient::new(deno_exe, false)?;
-
- let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
- let (_, maybe_err) =
- client.write_request::<_, _, Value>("initialize", params)?;
- assert!(maybe_err.is_none());
- client.write_notification("initialized", json!({}))?;
+ let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
+ client.initialize_default();
client.write_notification(
"textDocument/didOpen",
@@ -189,13 +176,8 @@ fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
}
fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {
- let mut client = LspClient::new(deno_exe, false)?;
-
- let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
- let (_, maybe_err) =
- client.write_request::<_, _, Value>("initialize", params)?;
- assert!(maybe_err.is_none());
- client.write_notification("initialized", json!({}))?;
+ let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
+ client.initialize_default();
for i in 0..10 {
client.write_notification(
@@ -285,14 +267,8 @@ fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {
/// A test that starts up the LSP, opens a single line document, and exits.
fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
- let mut client = LspClient::new(deno_exe, false)?;
-
- let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
- let (_, response_error) =
- client.write_request::<_, _, Value>("initialize", params)?;
- assert!(response_error.is_none());
-
- client.write_notification("initialized", json!({}))?;
+ let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
+ client.initialize_default();
client.write_notification(
"textDocument/didOpen",
diff --git a/cli/bench/lsp_bench_standalone.rs b/cli/bench/lsp_bench_standalone.rs
index e8dc29073..888d959ac 100644
--- a/cli/bench/lsp_bench_standalone.rs
+++ b/cli/bench/lsp_bench_standalone.rs
@@ -3,25 +3,16 @@
use deno_bench_util::bencher::benchmark_group;
use deno_bench_util::bencher::benchmark_main;
use deno_bench_util::bencher::Bencher;
-use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use test_util::lsp::LspClient;
+use test_util::lsp::LspClientBuilder;
// Intended to match the benchmark in quick-lint-js
// https://github.com/quick-lint/quick-lint-js/blob/35207e6616267c6c81be63f47ce97ec2452d60df/benchmark/benchmark-lsp/lsp-benchmarks.cpp#L223-L268
fn incremental_change_wait(bench: &mut Bencher) {
- let deno_exe = test_util::deno_exe_path();
- let mut client = LspClient::new(&deno_exe, false).unwrap();
-
- static FIXTURE_INIT_JSON: &[u8] =
- include_bytes!("testdata/initialize_params.json");
- let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON).unwrap();
- let (_, maybe_err) = client
- .write_request::<_, _, Value>("initialize", params)
- .unwrap();
- assert!(maybe_err.is_none());
- client.write_notification("initialized", json!({})).unwrap();
+ let mut client = LspClientBuilder::new().build();
+ client.initialize_default();
client
.write_notification(