1use std::{borrow::Cow, fs};
2
3use owo_colors::OwoColorize;
4use serde::{Deserialize, Serialize};
5use tabled::{Style, Table, Tabled};
6
7#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
8struct BenchSuite {
9 suite: String,
10 node_duration: String,
11 rust_duration: String,
12 rust_speedup: String,
13 is_faster: bool,
14}
15
16impl Tabled for BenchSuite {
17 const LENGTH: usize = 4;
18
19 fn fields(&self) -> Vec<Cow<str>> {
20 fn g(s: &str) -> Cow<str> {
21 Cow::Owned(s.green().to_string())
22 }
23 fn r(s: &str) -> Cow<str> {
24 Cow::Owned(s.red().to_string())
25 }
26 if self.is_faster {
27 [
28 g(&self.suite),
29 r(&self.node_duration),
30 g(&self.rust_duration),
31 g(&self.rust_speedup),
32 ]
33 } else {
34 [
35 r(&self.suite),
36 g(&self.node_duration),
37 r(&self.rust_duration),
38 r(&self.rust_speedup),
39 ]
40 }
41 .into_iter()
42 .collect()
43 }
44
45 fn headers() -> Vec<Cow<'static, str>> {
46 ["Suite", "@vercel/nft duration", "Rust duration", "Speedup"]
47 .map(Cow::Borrowed)
48 .into_iter()
49 .collect()
50 }
51}
52
53pub fn show_result() {
54 let bench_result_raw = fs::read_to_string("crates/turbopack/bench.json").unwrap();
55 let mut results = bench_result_raw
56 .lines()
57 .flat_map(|line| {
58 let suite: Vec<BenchSuite> = serde_json::from_str(line).unwrap();
59 suite
60 })
61 .collect::<Vec<_>>();
62 results.sort();
63 println!("{}", Table::new(results).with(Style::modern()));
64}