@@ -68,43 +68,43 @@ macro_rules! base_main {
6868 fn main( ) {
6969 let mut opt = $crate:: args( YEAR ) . get_matches( ) ;
7070
71- if opt. is_present( "bench" ) {
72- bench( ) ;
73- } else {
74- let days: Vec <_> = {
75- if let Some ( opt_days) = opt. values_of( "days" ) {
76- let opt_days: Vec <_> = opt_days. collect( ) ;
77- let days = parse! { extract_day { } ; $( $tail ) * } ;
78-
79- let ignored_days: Vec <_> = opt_days
80- . iter( )
81- . filter( |day| !days. contains( & format!( "day{}" , day) . as_str( ) ) )
82- . copied( )
83- . collect( ) ;
84-
85- if !ignored_days. is_empty( ) {
86- eprintln!( r"/!\ Ignoring unimplemented days: {}" , ignored_days. join( ", " ) ) ;
87- }
88-
89- opt_days
90- . into_iter( )
91- . filter( |day| days. contains( & format!( "day{}" , day) . as_str( ) ) )
92- . collect( )
93- } else if opt. is_present( "all" ) {
94- parse!( extract_day { } ; $( $tail ) * )
95- . iter( )
96- . map( |s| & s[ 3 ..] )
97- . collect( )
98- } else {
99- // Get most recent day, assuming the days are sorted
100- vec![ parse!( extract_day { } ; $( $tail ) * )
101- . iter( )
102- . map( |s| & s[ 3 ..] )
103- . last( )
104- . expect( "No day implemenations found" ) ]
71+ let days: Vec <_> = {
72+ if let Some ( opt_days) = opt. values_of( "days" ) {
73+ let opt_days: Vec <_> = opt_days. collect( ) ;
74+ let days = parse! { extract_day { } ; $( $tail ) * } ;
75+
76+ let ignored_days: Vec <_> = opt_days
77+ . iter( )
78+ . filter( |day| !days. contains( & format!( "day{}" , day) . as_str( ) ) )
79+ . copied( )
80+ . collect( ) ;
81+
82+ if !ignored_days. is_empty( ) {
83+ eprintln!( r"/!\ Ignoring unimplemented days: {}" , ignored_days. join( ", " ) ) ;
10584 }
106- } ;
10785
86+ opt_days
87+ . into_iter( )
88+ . filter( |day| days. contains( & format!( "day{}" , day) . as_str( ) ) )
89+ . collect( )
90+ } else if opt. is_present( "all" ) {
91+ parse!( extract_day { } ; $( $tail ) * )
92+ . iter( )
93+ . map( |s| & s[ 3 ..] )
94+ . collect( )
95+ } else {
96+ // Get most recent day, assuming the days are sorted
97+ vec![ parse!( extract_day { } ; $( $tail ) * )
98+ . iter( )
99+ . map( |s| & s[ 3 ..] )
100+ . last( )
101+ . expect( "No day implemenations found" ) ]
102+ }
103+ } ;
104+
105+ if opt. is_present( "bench" ) {
106+ bench( days) ;
107+ } else {
108108 if days. len( ) > 1 && ( opt. is_present( "stdin" ) || opt. is_present( "file" ) ) {
109109 eprintln!( r"/!\ You are using a personalized output over several days which can" ) ;
110110 eprintln!( r" be missleading. If you only intend to run solutions for a" ) ;
@@ -130,13 +130,15 @@ macro_rules! main {
130130
131131 use $crate:: criterion:: Criterion ;
132132
133- fn bench( ) {
134- let mut criterion = Criterion :: default ( ) . configure_from_args ( ) ;
133+ fn bench( days : Vec < & str > ) {
134+ let mut criterion = Criterion :: default ( ) . with_output_color ( true ) ;
135135
136- parse! {
137- bench_day { & mut criterion, YEAR } ;
138- $( $tail ) *
139- } ;
136+ for day in days. into_iter( ) {
137+ parse! {
138+ bench_day { & mut criterion, format!( "day{}" , day) , YEAR } ;
139+ $( $tail ) *
140+ } ;
141+ }
140142
141143 criterion. final_summary( ) ;
142144 }
@@ -149,7 +151,7 @@ macro_rules! main {
149151 ( year $year: expr; $( $tail: tt ) * ) => {
150152 $crate:: base_main! { year $year; $( $tail ) * }
151153
152- fn bench( ) {
154+ fn bench( days : Vec < & str > ) {
153155 println!( "Benchmarks not available, please enable `bench` feature for cargo-main." ) ;
154156 }
155157 }
0 commit comments