2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-08-28 09:03:50 -04:00
|
|
|
|
2021-01-27 22:50:14 -05:00
|
|
|
use deno_core::error::AnyError;
|
2021-02-25 00:14:17 -05:00
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::serde_json::Value;
|
2021-01-17 11:40:29 -05:00
|
|
|
use serde::Serialize;
|
2021-02-25 00:14:17 -05:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::convert::From;
|
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
2021-03-25 14:17:37 -04:00
|
|
|
use std::path::Path;
|
2021-02-25 00:14:17 -05:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::process::Command;
|
|
|
|
use std::process::Stdio;
|
2021-01-17 11:40:29 -05:00
|
|
|
use std::time::SystemTime;
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
mod http;
|
2021-02-25 00:14:17 -05:00
|
|
|
mod lsp;
|
2020-08-28 09:03:50 -04:00
|
|
|
|
2020-09-05 20:34:02 -04:00
|
|
|
fn read_json(filename: &str) -> Result<Value> {
|
2020-08-28 09:03:50 -04:00
|
|
|
let f = fs::File::open(filename)?;
|
|
|
|
Ok(serde_json::from_reader(f)?)
|
|
|
|
}
|
|
|
|
|
2020-09-05 20:34:02 -04:00
|
|
|
fn write_json(filename: &str, value: &Value) -> Result<()> {
|
2020-08-28 09:03:50 -04:00
|
|
|
let f = fs::File::create(filename)?;
|
|
|
|
serde_json::to_writer(f, value)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The list of the tuples of the benchmark name, arguments and return code
|
|
|
|
const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
|
2020-10-01 06:32:05 -04:00
|
|
|
// we need to run the cold_* benchmarks before the _warm_ ones as they ensure
|
|
|
|
// the cache is properly populated, instead of other tests possibly
|
|
|
|
// invalidating that cache.
|
2020-08-28 09:03:50 -04:00
|
|
|
(
|
|
|
|
"cold_hello",
|
2021-08-11 10:20:47 -04:00
|
|
|
&["run", "--reload", "cli/tests/testdata/002_hello.ts"],
|
2020-08-28 09:03:50 -04:00
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"cold_relative_import",
|
2021-08-11 10:20:47 -04:00
|
|
|
&[
|
|
|
|
"run",
|
|
|
|
"--reload",
|
|
|
|
"cli/tests/testdata/003_relative_import.ts",
|
|
|
|
],
|
2020-08-28 09:03:50 -04:00
|
|
|
None,
|
|
|
|
),
|
2021-08-11 10:20:47 -04:00
|
|
|
("hello", &["run", "cli/tests/testdata/002_hello.ts"], None),
|
2020-10-01 06:32:05 -04:00
|
|
|
(
|
|
|
|
"relative_import",
|
2021-08-11 10:20:47 -04:00
|
|
|
&["run", "cli/tests/testdata/003_relative_import.ts"],
|
2020-10-01 06:32:05 -04:00
|
|
|
None,
|
|
|
|
),
|
2021-08-11 10:20:47 -04:00
|
|
|
(
|
|
|
|
"error_001",
|
|
|
|
&["run", "cli/tests/testdata/error_001.ts"],
|
|
|
|
Some(1),
|
|
|
|
),
|
2020-09-14 06:25:06 -04:00
|
|
|
(
|
|
|
|
"no_check_hello",
|
2021-08-11 10:20:47 -04:00
|
|
|
&[
|
|
|
|
"run",
|
|
|
|
"--reload",
|
|
|
|
"--no-check",
|
|
|
|
"cli/tests/testdata/002_hello.ts",
|
|
|
|
],
|
2020-09-14 06:25:06 -04:00
|
|
|
None,
|
|
|
|
),
|
2020-08-28 09:03:50 -04:00
|
|
|
(
|
|
|
|
"workers_startup",
|
2021-08-11 10:20:47 -04:00
|
|
|
&[
|
|
|
|
"run",
|
|
|
|
"--allow-read",
|
|
|
|
"cli/tests/testdata/workers/bench_startup.ts",
|
|
|
|
],
|
2020-08-28 09:03:50 -04:00
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"workers_round_robin",
|
|
|
|
&[
|
|
|
|
"run",
|
|
|
|
"--allow-read",
|
2021-08-11 10:20:47 -04:00
|
|
|
"cli/tests/testdata/workers/bench_round_robin.ts",
|
2020-08-28 09:03:50 -04:00
|
|
|
],
|
|
|
|
None,
|
|
|
|
),
|
2021-02-23 07:08:50 -05:00
|
|
|
(
|
|
|
|
"workers_large_message",
|
|
|
|
&[
|
|
|
|
"run",
|
|
|
|
"--allow-read",
|
2021-08-11 10:20:47 -04:00
|
|
|
"cli/tests/testdata/workers/bench_large_message.ts",
|
2021-02-23 07:08:50 -05:00
|
|
|
],
|
|
|
|
None,
|
|
|
|
),
|
2020-08-28 09:03:50 -04:00
|
|
|
(
|
|
|
|
"text_decoder",
|
2021-08-11 10:20:47 -04:00
|
|
|
&["run", "cli/tests/testdata/text_decoder_perf.js"],
|
2020-08-28 09:03:50 -04:00
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"text_encoder",
|
2021-08-11 10:20:47 -04:00
|
|
|
&["run", "cli/tests/testdata/text_encoder_perf.js"],
|
2020-08-28 09:03:50 -04:00
|
|
|
None,
|
|
|
|
),
|
2021-05-08 17:31:40 -04:00
|
|
|
(
|
|
|
|
"text_encoder_into",
|
2021-08-11 10:20:47 -04:00
|
|
|
&["run", "cli/tests/testdata/text_encoder_into_perf.js"],
|
2021-05-08 17:31:40 -04:00
|
|
|
None,
|
|
|
|
),
|
2021-09-25 09:30:31 -04:00
|
|
|
(
|
|
|
|
"response_string",
|
|
|
|
&["run", "cli/tests/testdata/response_string_perf.js"],
|
|
|
|
None,
|
|
|
|
),
|
2020-08-28 09:03:50 -04:00
|
|
|
(
|
|
|
|
"check",
|
2021-02-02 06:05:46 -05:00
|
|
|
&[
|
|
|
|
"cache",
|
|
|
|
"--reload",
|
|
|
|
"test_util/std/examples/chat/server_test.ts",
|
|
|
|
],
|
2020-08-28 09:03:50 -04:00
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no_check",
|
|
|
|
&[
|
|
|
|
"cache",
|
|
|
|
"--reload",
|
|
|
|
"--no-check",
|
2021-02-02 06:05:46 -05:00
|
|
|
"test_util/std/examples/chat/server_test.ts",
|
2020-08-28 09:03:50 -04:00
|
|
|
],
|
|
|
|
None,
|
|
|
|
),
|
2020-10-05 06:39:46 -04:00
|
|
|
(
|
|
|
|
"bundle",
|
2021-02-02 06:05:46 -05:00
|
|
|
&["bundle", "test_util/std/examples/chat/server_test.ts"],
|
2020-10-05 06:39:46 -04:00
|
|
|
None,
|
|
|
|
),
|
2020-10-26 14:57:29 -04:00
|
|
|
(
|
|
|
|
"bundle_no_check",
|
2021-02-02 06:05:46 -05:00
|
|
|
&[
|
|
|
|
"bundle",
|
|
|
|
"--no-check",
|
|
|
|
"test_util/std/examples/chat/server_test.ts",
|
|
|
|
],
|
2020-10-26 14:57:29 -04:00
|
|
|
None,
|
|
|
|
),
|
2020-08-28 09:03:50 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
const RESULT_KEYS: &[&str] =
|
|
|
|
&["mean", "stddev", "user", "system", "min", "max"];
|
2021-01-17 11:40:29 -05:00
|
|
|
fn run_exec_time(
|
2021-03-25 14:17:37 -04:00
|
|
|
deno_exe: &Path,
|
|
|
|
target_dir: &Path,
|
2021-01-17 11:40:29 -05:00
|
|
|
) -> Result<HashMap<String, HashMap<String, f64>>> {
|
2020-08-28 09:03:50 -04:00
|
|
|
let hyperfine_exe = test_util::prebuilt_tool_path("hyperfine");
|
|
|
|
|
|
|
|
let benchmark_file = target_dir.join("hyperfine_results.json");
|
|
|
|
let benchmark_file = benchmark_file.to_str().unwrap();
|
|
|
|
|
|
|
|
let mut command = [
|
|
|
|
hyperfine_exe.to_str().unwrap(),
|
|
|
|
"--export-json",
|
|
|
|
benchmark_file,
|
|
|
|
"--warmup",
|
|
|
|
"3",
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
for (_, args, return_code) in EXEC_TIME_BENCHMARKS {
|
|
|
|
let ret_code_test = if let Some(code) = return_code {
|
|
|
|
// Bash test which asserts the return code value of the previous command
|
|
|
|
// $? contains the return code of the previous command
|
|
|
|
format!("; test $? -eq {}", code)
|
|
|
|
} else {
|
|
|
|
"".to_string()
|
|
|
|
};
|
|
|
|
command.push(format!(
|
|
|
|
"{} {} {}",
|
|
|
|
deno_exe.to_str().unwrap(),
|
|
|
|
args.join(" "),
|
|
|
|
ret_code_test
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
test_util::run(
|
|
|
|
&command.iter().map(|s| s.as_ref()).collect::<Vec<_>>(),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
let mut results = HashMap::<String, HashMap<String, f64>>::new();
|
2020-08-28 09:03:50 -04:00
|
|
|
let hyperfine_results = read_json(benchmark_file)?;
|
|
|
|
for ((name, _, _), data) in EXEC_TIME_BENCHMARKS.iter().zip(
|
|
|
|
hyperfine_results
|
|
|
|
.as_object()
|
|
|
|
.unwrap()
|
|
|
|
.get("results")
|
|
|
|
.unwrap()
|
|
|
|
.as_array()
|
|
|
|
.unwrap(),
|
|
|
|
) {
|
|
|
|
let data = data.as_object().unwrap().clone();
|
|
|
|
results.insert(
|
|
|
|
name.to_string(),
|
2021-01-17 11:40:29 -05:00
|
|
|
data
|
|
|
|
.into_iter()
|
|
|
|
.filter(|(key, _)| RESULT_KEYS.contains(&key.as_str()))
|
|
|
|
.map(|(key, val)| (key, val.as_f64().unwrap()))
|
|
|
|
.collect(),
|
2020-08-28 09:03:50 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
Ok(results)
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
2021-01-05 16:28:51 -05:00
|
|
|
fn rlib_size(target_dir: &std::path::Path, prefix: &str) -> u64 {
|
|
|
|
let mut size = 0;
|
|
|
|
let mut seen = std::collections::HashSet::new();
|
|
|
|
for entry in std::fs::read_dir(target_dir.join("deps")).unwrap() {
|
|
|
|
let entry = entry.unwrap();
|
|
|
|
let os_str = entry.file_name();
|
|
|
|
let name = os_str.to_str().unwrap();
|
|
|
|
if name.starts_with(prefix) && name.ends_with(".rlib") {
|
|
|
|
let start = name.split('-').next().unwrap().to_string();
|
|
|
|
if seen.contains(&start) {
|
|
|
|
println!("skip {}", name);
|
|
|
|
} else {
|
|
|
|
seen.insert(start);
|
|
|
|
size += entry.metadata().unwrap().len();
|
|
|
|
println!("check size {} {}", name, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert!(size > 0);
|
|
|
|
size
|
|
|
|
}
|
|
|
|
|
2020-08-28 09:03:50 -04:00
|
|
|
const BINARY_TARGET_FILES: &[&str] =
|
|
|
|
&["CLI_SNAPSHOT.bin", "COMPILER_SNAPSHOT.bin"];
|
2021-03-25 14:17:37 -04:00
|
|
|
fn get_binary_sizes(target_dir: &Path) -> Result<HashMap<String, u64>> {
|
2021-01-17 11:40:29 -05:00
|
|
|
let mut sizes = HashMap::<String, u64>::new();
|
|
|
|
let mut mtimes = HashMap::<String, SystemTime>::new();
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
sizes.insert(
|
|
|
|
"deno".to_string(),
|
2021-01-17 11:40:29 -05:00
|
|
|
test_util::deno_exe_path().metadata()?.len(),
|
2020-08-28 09:03:50 -04:00
|
|
|
);
|
|
|
|
|
2021-01-05 16:28:51 -05:00
|
|
|
// add up size for everything in target/release/deps/libswc*
|
2021-07-30 09:03:41 -04:00
|
|
|
let swc_size = rlib_size(target_dir, "libswc");
|
2021-01-05 16:28:51 -05:00
|
|
|
println!("swc {} bytes", swc_size);
|
2021-01-17 11:40:29 -05:00
|
|
|
sizes.insert("swc_rlib".to_string(), swc_size);
|
2021-01-05 16:28:51 -05:00
|
|
|
|
2021-10-28 06:40:27 -04:00
|
|
|
let v8_size = rlib_size(target_dir, "libv8");
|
|
|
|
println!("v8 {} bytes", v8_size);
|
|
|
|
sizes.insert("rusty_v8_rlib".to_string(), v8_size);
|
2021-01-05 16:28:51 -05:00
|
|
|
|
2020-08-28 09:03:50 -04:00
|
|
|
// Because cargo's OUT_DIR is not predictable, search the build tree for
|
|
|
|
// snapshot related files.
|
|
|
|
for file in walkdir::WalkDir::new(target_dir) {
|
2020-11-12 17:17:31 -05:00
|
|
|
let file = match file {
|
|
|
|
Ok(file) => file,
|
|
|
|
Err(_) => continue,
|
|
|
|
};
|
2020-08-28 09:03:50 -04:00
|
|
|
let filename = file.file_name().to_str().unwrap().to_string();
|
|
|
|
|
|
|
|
if !BINARY_TARGET_FILES.contains(&filename.as_str()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let meta = file.metadata()?;
|
|
|
|
let file_mtime = meta.modified()?;
|
|
|
|
|
|
|
|
// If multiple copies of a file are found, use the most recent one.
|
|
|
|
if let Some(stored_mtime) = mtimes.get(&filename) {
|
|
|
|
if *stored_mtime > file_mtime {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mtimes.insert(filename.clone(), file_mtime);
|
2021-01-17 11:40:29 -05:00
|
|
|
sizes.insert(filename, meta.len());
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
Ok(sizes)
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const BUNDLES: &[(&str, &str)] = &[
|
2021-02-02 06:05:46 -05:00
|
|
|
("file_server", "./test_util/std/http/file_server.ts"),
|
|
|
|
("gist", "./test_util/std/examples/gist.ts"),
|
2020-08-28 09:03:50 -04:00
|
|
|
];
|
2021-03-25 14:17:37 -04:00
|
|
|
fn bundle_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
|
2021-01-17 11:40:29 -05:00
|
|
|
let mut sizes = HashMap::<String, u64>::new();
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
for (name, url) in BUNDLES {
|
|
|
|
let path = format!("{}.bundle.js", name);
|
|
|
|
test_util::run(
|
|
|
|
&[
|
|
|
|
deno_exe.to_str().unwrap(),
|
|
|
|
"bundle",
|
|
|
|
"--unstable",
|
|
|
|
url,
|
|
|
|
&path,
|
|
|
|
],
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
let file = PathBuf::from(path);
|
|
|
|
assert!(file.is_file());
|
2021-01-17 11:40:29 -05:00
|
|
|
sizes.insert(name.to_string(), file.metadata()?.len());
|
2020-08-28 09:03:50 -04:00
|
|
|
let _ = fs::remove_file(file);
|
|
|
|
}
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
Ok(sizes)
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
2021-03-25 14:17:37 -04:00
|
|
|
fn run_http(target_dir: &Path, new_data: &mut BenchResult) -> Result<()> {
|
2020-08-28 09:03:50 -04:00
|
|
|
let stats = http::benchmark(target_dir)?;
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
new_data.req_per_sec = stats
|
|
|
|
.iter()
|
|
|
|
.map(|(name, result)| (name.clone(), result.requests))
|
|
|
|
.collect();
|
2020-08-28 09:03:50 -04:00
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
new_data.max_latency = stats
|
|
|
|
.iter()
|
|
|
|
.map(|(name, result)| (name.clone(), result.latency))
|
|
|
|
.collect();
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run_strace_benchmarks(
|
2021-03-25 14:17:37 -04:00
|
|
|
deno_exe: &Path,
|
2021-01-17 11:40:29 -05:00
|
|
|
new_data: &mut BenchResult,
|
2020-08-28 09:03:50 -04:00
|
|
|
) -> Result<()> {
|
|
|
|
use std::io::Read;
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
let mut thread_count = HashMap::<String, u64>::new();
|
|
|
|
let mut syscall_count = HashMap::<String, u64>::new();
|
2020-08-28 09:03:50 -04:00
|
|
|
|
2021-05-11 18:06:58 -04:00
|
|
|
for (name, args, expected_exit_code) in EXEC_TIME_BENCHMARKS {
|
2022-04-01 11:15:37 -04:00
|
|
|
let mut file = secure_tempfile::NamedTempFile::new()?;
|
2020-08-28 09:03:50 -04:00
|
|
|
|
2021-05-11 18:06:58 -04:00
|
|
|
let exit_status = Command::new("strace")
|
2020-08-28 09:03:50 -04:00
|
|
|
.args(&[
|
|
|
|
"-c",
|
|
|
|
"-f",
|
|
|
|
"-o",
|
|
|
|
file.path().to_str().unwrap(),
|
|
|
|
deno_exe.to_str().unwrap(),
|
|
|
|
])
|
|
|
|
.args(args.iter())
|
2021-05-11 18:06:58 -04:00
|
|
|
.stdout(Stdio::null())
|
2020-08-28 09:03:50 -04:00
|
|
|
.spawn()?
|
|
|
|
.wait()?;
|
2021-05-11 18:06:58 -04:00
|
|
|
let expected_exit_code = expected_exit_code.unwrap_or(0);
|
|
|
|
assert_eq!(exit_status.code(), Some(expected_exit_code));
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
let mut output = String::new();
|
|
|
|
file.as_file_mut().read_to_string(&mut output)?;
|
|
|
|
|
|
|
|
let strace_result = test_util::parse_strace_output(&output);
|
2021-01-18 05:00:51 -05:00
|
|
|
let clone = strace_result.get("clone").map(|d| d.calls).unwrap_or(0) + 1;
|
2021-01-17 11:40:29 -05:00
|
|
|
let total = strace_result.get("total").unwrap().calls;
|
|
|
|
thread_count.insert(name.to_string(), clone);
|
|
|
|
syscall_count.insert(name.to_string(), total);
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
new_data.thread_count = thread_count;
|
|
|
|
new_data.syscall_count = syscall_count;
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-03-25 14:17:37 -04:00
|
|
|
fn run_max_mem_benchmark(deno_exe: &Path) -> Result<HashMap<String, u64>> {
|
2021-01-17 11:40:29 -05:00
|
|
|
let mut results = HashMap::<String, u64>::new();
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
for (name, args, return_code) in EXEC_TIME_BENCHMARKS {
|
|
|
|
let proc = Command::new("time")
|
|
|
|
.args(&["-v", deno_exe.to_str().unwrap()])
|
|
|
|
.args(args.iter())
|
|
|
|
.stdout(Stdio::null())
|
|
|
|
.stderr(Stdio::piped())
|
|
|
|
.spawn()?;
|
|
|
|
|
|
|
|
let proc_result = proc.wait_with_output()?;
|
|
|
|
if let Some(code) = return_code {
|
|
|
|
assert_eq!(proc_result.status.code().unwrap(), *code);
|
|
|
|
}
|
|
|
|
let out = String::from_utf8(proc_result.stderr)?;
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
results.insert(name.to_string(), test_util::parse_max_mem(&out).unwrap());
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
Ok(results)
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
2021-01-10 08:13:38 -05:00
|
|
|
fn cargo_deps() -> usize {
|
|
|
|
let cargo_lock = test_util::root_path().join("Cargo.lock");
|
|
|
|
let mut count = 0;
|
|
|
|
let file = std::fs::File::open(cargo_lock).unwrap();
|
|
|
|
use std::io::BufRead;
|
|
|
|
for line in std::io::BufReader::new(file).lines() {
|
|
|
|
if line.unwrap().starts_with("[[package]]") {
|
|
|
|
count += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
println!("cargo_deps {}", count);
|
|
|
|
assert!(count > 10); // Sanity check.
|
|
|
|
count
|
|
|
|
}
|
|
|
|
|
2021-02-25 00:14:17 -05:00
|
|
|
#[derive(Default, Serialize)]
|
2021-01-17 11:40:29 -05:00
|
|
|
struct BenchResult {
|
|
|
|
created_at: String,
|
|
|
|
sha1: String,
|
2021-02-25 00:14:17 -05:00
|
|
|
|
2021-01-17 11:40:29 -05:00
|
|
|
// TODO(ry) The "benchmark" benchmark should actually be called "exec_time".
|
|
|
|
// When this is changed, the historical data in gh-pages branch needs to be
|
|
|
|
// changed too.
|
|
|
|
benchmark: HashMap<String, HashMap<String, f64>>,
|
2021-02-25 00:14:17 -05:00
|
|
|
binary_size: HashMap<String, u64>,
|
|
|
|
bundle_size: HashMap<String, u64>,
|
|
|
|
cargo_deps: usize,
|
|
|
|
max_latency: HashMap<String, f64>,
|
2021-01-17 11:40:29 -05:00
|
|
|
max_memory: HashMap<String, u64>,
|
2021-02-25 00:14:17 -05:00
|
|
|
lsp_exec_time: HashMap<String, u64>,
|
2021-01-17 11:40:29 -05:00
|
|
|
req_per_sec: HashMap<String, u64>,
|
|
|
|
syscall_count: HashMap<String, u64>,
|
2021-02-25 00:14:17 -05:00
|
|
|
thread_count: HashMap<String, u64>,
|
2021-01-17 11:40:29 -05:00
|
|
|
}
|
|
|
|
|
2020-08-28 09:03:50 -04:00
|
|
|
/*
|
|
|
|
TODO(SyrupThinker)
|
|
|
|
Switch to the #[bench] attribute once
|
|
|
|
it is stabilized.
|
|
|
|
Before that the #[test] tests won't be run because
|
|
|
|
we replace the harness with our own runner here.
|
|
|
|
*/
|
|
|
|
fn main() -> Result<()> {
|
2021-06-17 15:56:30 -04:00
|
|
|
if !env::args().any(|s| s == "--bench") {
|
2020-08-28 09:03:50 -04:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("Starting Deno benchmark");
|
|
|
|
|
|
|
|
let target_dir = test_util::target_dir();
|
|
|
|
let deno_exe = test_util::deno_exe_path();
|
|
|
|
|
|
|
|
env::set_current_dir(&test_util::root_path())?;
|
|
|
|
|
2021-02-25 00:14:17 -05:00
|
|
|
let mut new_data = BenchResult {
|
|
|
|
created_at: chrono::Utc::now()
|
|
|
|
.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
|
|
|
sha1: test_util::run_collect(
|
|
|
|
&["git", "rev-parse", "HEAD"],
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
.0
|
|
|
|
.trim()
|
|
|
|
.to_string(),
|
|
|
|
benchmark: run_exec_time(&deno_exe, &target_dir)?,
|
|
|
|
binary_size: get_binary_sizes(&target_dir)?,
|
|
|
|
bundle_size: bundle_benchmark(&deno_exe)?,
|
|
|
|
cargo_deps: cargo_deps(),
|
|
|
|
lsp_exec_time: lsp::benchmarks(&deno_exe)?,
|
|
|
|
..Default::default()
|
|
|
|
};
|
2020-08-28 09:03:50 -04:00
|
|
|
|
|
|
|
if cfg!(not(target_os = "windows")) {
|
|
|
|
run_http(&target_dir, &mut new_data)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
run_strace_benchmarks(&deno_exe, &mut new_data)?;
|
2021-01-17 11:40:29 -05:00
|
|
|
new_data.max_memory = run_max_mem_benchmark(&deno_exe)?;
|
2020-08-28 09:03:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
println!("===== <BENCHMARK RESULTS>");
|
|
|
|
serde_json::to_writer_pretty(std::io::stdout(), &new_data)?;
|
|
|
|
println!("\n===== </BENCHMARK RESULTS>");
|
|
|
|
|
|
|
|
if let Some(filename) = target_dir.join("bench.json").to_str() {
|
2021-01-17 11:40:29 -05:00
|
|
|
write_json(filename, &serde_json::to_value(&new_data)?)?;
|
2020-08-28 09:03:50 -04:00
|
|
|
} else {
|
|
|
|
eprintln!("Cannot write bench.json, path is invalid");
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-03-23 09:54:22 -04:00
|
|
|
pub type Result<T> = std::result::Result<T, AnyError>;
|