1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

benchmarks: fix exec_time and latency benchmarks (#15155)

This commit is contained in:
Bartek Iwańczuk 2022-07-11 20:58:32 +02:00 committed by GitHub
parent 989c723130
commit 88c36fd414
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View file

@ -162,7 +162,7 @@ const RESULT_KEYS: &[&str] =
fn run_exec_time(
deno_exe: &Path,
target_dir: &Path,
) -> Result<HashMap<String, HashMap<String, i64>>> {
) -> Result<HashMap<String, HashMap<String, f64>>> {
let hyperfine_exe = test_util::prebuilt_tool_path("hyperfine");
let benchmark_file = target_dir.join("hyperfine_results.json");
@ -203,7 +203,7 @@ fn run_exec_time(
true,
);
let mut results = HashMap::<String, HashMap<String, i64>>::new();
let mut results = HashMap::<String, HashMap<String, f64>>::new();
let hyperfine_results = read_json(benchmark_file)?;
for ((name, _, _), data) in EXEC_TIME_BENCHMARKS.iter().zip(
hyperfine_results
@ -220,7 +220,7 @@ fn run_exec_time(
data
.into_iter()
.filter(|(key, _)| RESULT_KEYS.contains(&key.as_str()))
.map(|(key, val)| (key, val.as_f64().unwrap() as i64))
.map(|(key, val)| (key, val.as_f64().unwrap()))
.collect(),
);
}
@ -382,11 +382,11 @@ struct BenchResult {
// 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, i64>>,
benchmark: HashMap<String, HashMap<String, f64>>,
binary_size: HashMap<String, i64>,
bundle_size: HashMap<String, i64>,
cargo_deps: usize,
max_latency: HashMap<String, i64>,
max_latency: HashMap<String, f64>,
max_memory: HashMap<String, i64>,
lsp_exec_time: HashMap<String, i64>,
req_per_sec: HashMap<String, i64>,
@ -489,7 +489,7 @@ async fn main() -> Result<()> {
new_data.req_per_sec = req_per_sec;
let max_latency = stats
.iter()
.map(|(name, result)| (name.clone(), result.latency as i64))
.map(|(name, result)| (name.clone(), result.latency))
.collect();
reporter.write("max_latency", &max_latency);

View file

@ -17,9 +17,9 @@ static GIT_HASH: Lazy<String> = Lazy::new(|| {
});
#[derive(serde::Serialize)]
struct Metric {
struct Metric<T: serde::Serialize> {
name: String,
value: i64,
value: T,
sha1: String,
#[serde(rename = "type")]
type_: String,
@ -62,7 +62,12 @@ impl Reporter {
}
}
pub fn write_one(&mut self, type_: &str, name: &str, value: i64) {
pub fn write_one<T: serde::Serialize>(
&mut self,
type_: &str,
name: &str,
value: T,
) {
self
.wtr
.serialize(Metric {
@ -75,7 +80,11 @@ impl Reporter {
.unwrap();
}
pub fn write(&mut self, type_: &str, hashmap: &HashMap<String, i64>) {
pub fn write<T: serde::Serialize + Copy>(
&mut self,
type_: &str,
hashmap: &HashMap<String, T>,
) {
for (name, value) in hashmap {
self.write_one(type_, name, *value);
}