Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Sep 15, 2021
1 parent b321aeb commit 8d8a5af
Showing 1 changed file with 77 additions and 23 deletions.
100 changes: 77 additions & 23 deletions src/runnner/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,9 @@ fn display_costs_report() {

for (contract_id, methods) in consolidated.iter() {
for (method, reports) in methods.iter() {

let (min, min_report, min_bottleneck) = mins.get(&(contract_id, method)).unwrap();
let (max, max_report, max_bottleneck) = mins.get(&(contract_id, method)).unwrap();

// Not displaying the min row for now - probably not so interesting atm.
// if min != max {
// table.add_row(Row::new(formatted_cost_cells(
Expand Down Expand Up @@ -612,7 +611,10 @@ fn display_costs_report() {

table.add_row(Row::new(vec![
Cell::new("Mainnet Block Limits (Stacks 2.0)"),
Cell::new_align(&format!("{}", &limit.runtime.to_string()), format::Alignment::RIGHT),
Cell::new_align(
&format!("{}", &limit.runtime.to_string()),
format::Alignment::RIGHT,
),
Cell::new_align(&limit.read_count.to_string(), format::Alignment::RIGHT),
Cell::new_align(&format!("{}", limit.read_length), format::Alignment::RIGHT),
Cell::new_align(&limit.write_count.to_string(), format::Alignment::RIGHT),
Expand Down Expand Up @@ -665,31 +667,83 @@ fn formatted_cost_cells(title: &str, report: &CostsReport, bottleneck: &Bottlene
};

let ratios = vec![
(report.cost_result.total.runtime, report.cost_result.limit.runtime),
(report.cost_result.total.read_count, report.cost_result.limit.read_count),
(report.cost_result.total.read_length, report.cost_result.limit.read_length),
(report.cost_result.total.write_count, report.cost_result.limit.write_count),
(report.cost_result.total.write_length, report.cost_result.limit.write_length),
(
report.cost_result.total.runtime,
report.cost_result.limit.runtime,
),
(
report.cost_result.total.read_count,
report.cost_result.limit.read_count,
),
(
report.cost_result.total.read_length,
report.cost_result.limit.read_length,
),
(
report.cost_result.total.write_count,
report.cost_result.limit.write_count,
),
(
report.cost_result.total.write_length,
report.cost_result.limit.write_length,
),
];

let annotations = ratios.iter().map(|(value, limit)| {
if *value == 0 {
"".to_string()
} else {
format!(" ({:.2}%)", 100.0 * *value as f32 / *limit as f32)
}
}).collect::<Vec<String>>();
let annotations = ratios
.iter()
.map(|(value, limit)| {
if *value == 0 {
"".to_string()
} else {
format!(" ({:.2}%)", 100.0 * *value as f32 / *limit as f32)
}
})
.collect::<Vec<String>>();

vec![
Cell::new(title),
Cell::new_align(&format!("{}{}", report.cost_result.total.runtime.to_string(), annotations[0]), format::Alignment::RIGHT).with_style(runtime_style),
Cell::new_align(&format!("{}{}", report.cost_result.total.read_count.to_string(), annotations[1]), format::Alignment::RIGHT).with_style(read_count_style),
Cell::new_align(&format!("{}{}", report.cost_result.total.read_length, annotations[2]), format::Alignment::RIGHT)
.with_style(read_len_style),
Cell::new_align(&format!("{}{}", report.cost_result.total.write_count.to_string(), annotations[3]), format::Alignment::RIGHT).with_style(write_count_style),
Cell::new_align(&format!("{}{}", report.cost_result.total.write_length, annotations[4]), format::Alignment::RIGHT)
.with_style(write_len_style),
Cell::new_align(&format!("{}", tx_per_block), format::Alignment::RIGHT).with_style(block_style),
Cell::new_align(
&format!(
"{}{}",
report.cost_result.total.runtime.to_string(),
annotations[0]
),
format::Alignment::RIGHT,
)
.with_style(runtime_style),
Cell::new_align(
&format!(
"{}{}",
report.cost_result.total.read_count.to_string(),
annotations[1]
),
format::Alignment::RIGHT,
)
.with_style(read_count_style),
Cell::new_align(
&format!("{}{}", report.cost_result.total.read_length, annotations[2]),
format::Alignment::RIGHT,
)
.with_style(read_len_style),
Cell::new_align(
&format!(
"{}{}",
report.cost_result.total.write_count.to_string(),
annotations[3]
),
format::Alignment::RIGHT,
)
.with_style(write_count_style),
Cell::new_align(
&format!(
"{}{}",
report.cost_result.total.write_length, annotations[4]
),
format::Alignment::RIGHT,
)
.with_style(write_len_style),
Cell::new_align(&format!("{}", tx_per_block), format::Alignment::RIGHT)
.with_style(block_style),
]
}

Expand Down

0 comments on commit 8d8a5af

Please sign in to comment.