use std::collections::HashSet; use crate::template::run_multi::run_multi; use crate::template::timings::Timings; use crate::template::{Day, all_days, readme_benchmarks, scaffolded_years}; /// Benchmarks solutions. /// /// - with a year and a day, a single solution is benched. /// - with only a year, the solutions of that year are benched. /// - without either, the solutions of every scaffolded year are benched. /// /// Unless `run_all` is set, solutions that are already fully benched in the stored timings are skipped /// (this does not apply to a single, explicitly requested day). pub fn handle(year: Option, day: Option, run_all: bool, store: bool) { let stored_timings = Timings::read_from_file(); let days_to_run: HashSet = day.map_or_else( || { let years = year.map_or_else(scaffolded_years, |y| vec![y]); let days = years.into_iter().flat_map(all_days); if run_all { days.collect() } else { // when the `--all` flag is not set, filter out days that are fully benched. days.filter(|day| !stored_timings.is_day_complete(*day)) .collect() } }, |day| HashSet::from([day]), ); let timings = run_multi(&days_to_run, true, true).unwrap(); if store { let merged_timings = stored_timings.merge(&timings); merged_timings.store_file().unwrap(); println!(); match readme_benchmarks::update(merged_timings) { Ok(()) => { println!("Stored updated benchmarks."); } Err(_) => { eprintln!("Failed to store updated benchmarks."); } } } }