@@ -648,6 +648,8 @@ def main():
648648 parser .add_argument ("-n" , "--dry-run" , action = "store_true" , help = "do not run" )
649649 parser .add_argument ("--no-build" , action = "store_true" , help = "do not build" )
650650
651+ parser .add_argument ("-C" , "--comparison" , action = "store_true" , help = "Show languages commparison" )
652+
651653 parser .add_argument ("n" , type = int , nargs = "*" , help = "filter by year or year/day" )
652654
653655 args = parser .parse_args ()
@@ -851,34 +853,37 @@ def main():
851853 )
852854
853855 # compute languages comparison
854- lines = []
855- puzzles = set (map (itemgetter (0 , 1 ), stats_elapsed .keys ()))
856- for lang1 , lang2 in itertools .combinations (languages , 2 ):
857- n , t1 , t2 = 0 , 0 , 0
858- for y , d in puzzles :
859- t = dict ((lang , t ) for (yy , dd , lang ), (t , _ ) in stats_elapsed .items () if (yy , dd ) == (y , d ))
860- if lang1 in t and lang2 in t :
861- n += 1
862- t1 += t [lang1 ]
863- t2 += t [lang2 ]
864- if n > 0 :
865- if t2 < t1 :
866- t1 , t2 = t2 , t1
867- lang1 , lang2 = lang2 , lang1
868- faster = t2 / t1
869- lines .append (
870- (
871- t1 / n ,
872- t2 / n ,
873- f"{ YELLOW } { lang1 :<7} { RESET } "
874- f" vs. { YELLOW } { lang2 :<7} { RESET } :"
875- f" { GREEN } { t1 / n :7.3f} s{ RESET } vs. { GREEN } { t2 / n :7.3f} s{ RESET } "
876- f" (x { faster :4.1f} faster) on { WHITE } { n :3} { RESET } puzzle{ 's' if n > 1 else '' } " ,
856+ if args .comparison :
857+ lines = []
858+ puzzles = set (map (itemgetter (0 , 1 ), stats_elapsed .keys ()))
859+ for lang1 , lang2 in itertools .combinations (languages , 2 ):
860+ n , t1 , t2 = 0 , 0 , 0
861+ for y , d in puzzles :
862+ t = dict ((lang , t ) for (yy , dd , lang ), (t , _ ) in stats_elapsed .items () if (yy , dd ) == (y , d ))
863+ if lang1 in t and lang2 in t :
864+ n += 1
865+ t1 += t [lang1 ]
866+ t2 += t [lang2 ]
867+ if n > 0 :
868+ if t2 < t1 :
869+ t1 , t2 = t2 , t1
870+ lang1 , lang2 = lang2 , lang1
871+ faster = t2 / t1
872+ lines .append (
873+ (
874+ t1 / n ,
875+ t2 / n ,
876+ f"{ YELLOW } { lang1 :<7} { RESET } "
877+ f" vs. { YELLOW } { lang2 :<7} { RESET } :"
878+ f" { GREEN } { t1 / n :7.3f} s{ RESET } vs. { GREEN } { t2 / n :7.3f} s{ RESET } "
879+ f" (x { faster :4.1f} faster) on { WHITE } { n :3} { RESET } puzzle{ 's' if n > 1 else '' } " ,
880+ )
877881 )
878- )
879- print ()
880- print ("LANGUAGES COMPARISON:" )
881- print ("\n " .join (map (itemgetter (2 ), sorted (lines ))))
882+ print ()
883+ print ("LANGUAGES COMPARISON:" )
884+ print ("\n " .join (map (itemgetter (2 ), sorted (lines ))))
885+ else :
886+ print ("Use option -C/--comparison to display timings comparison." )
882887
883888 if problems :
884889 print ()
0 commit comments