Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file display.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306openCoremoduleR=Analysis_result.RegressionmoduleC=Analysis_result.CoefficientmoduleMagnitude=Display_units.MagnitudemoduleWarnings=structletlong_running_benchmark_time_limit_nanos=1E8lethas_long_running_benchmarks=reffalseletcheck_for_long_running_benchmarks~(resp:Variable.t)~(pred:Variable.t)est=match(resp,pred)with|(`Nanos,`Runs)->ifest>=long_running_benchmark_time_limit_nanosthenhas_long_running_benchmarks:=true;|(_,_)->()letdisplay()=if!has_long_running_benchmarksthenprintf"Benchmarks that take 1ns to %s can be estimated precisely. For more reliable \n\
estimates, redesign your benchmark to have a shorter execution time.\n%!"(Time.Span.to_string(Time.Span.of_nslong_running_benchmark_time_limit_nanos))endmoduleRegr=structmoduleCoeff=structtypet={predictor:Variable.t;mutableunits:Display_units.t;mutablemagnitude:Magnitude.t;mutablehas_ci:bool;mutablesmallest:floatoption;mutablelargest:floatoption;}letcreateunitspredictor={predictor;units;has_ci=false;smallest=None;largest=None;magnitude=Magnitude.max;}letupdatetcoeff=letselectcmpnn_opt=matchn,n_optwith|n,None->Somen|n,Somem->Some(cmpnm)int.has_ci<-t.has_ci||C.has_ci95coeff;letest=C.estimatecoeffint.smallest<-selectminestt.smallest;t.largest<-selectmaxestt.largest;t.magnitude<-Magnitude.smallert.magnitude(Magnitude.magnitudet.unitsest)endtypet={responder:Variable.t;coeffs:Coeff.tarray;key:int;regression_name:stringoption;mutablehas_r_square:bool;}letcreateregr=letresponder=R.responderregrinletunits=Variable.get_unitsresponderin{responder;coeffs=Array.map(R.predictorsregr)~f:(Coeff.createunits);key=R.keyregr;regression_name=R.regression_nameregr;has_r_square=false;}letupdatet~regr=t.has_r_square<-t.has_r_square||R.has_r_squareregr;Array.iteri(R.coefficientsregr)~f:(funicoeff->Coeff.updatet.coeffs.(i)coeff)letcreate_coltstr~f=Ascii_table.Column.create_attr~align:Right~show:`If_not_emptystr(funres->matchAnalysis_result.find_keyrest.keywith|None->([],"?")|Someregr->fregr)letmake_columns~show_absolute_ci~show_all_values~show_overheadst=letappend_name~estcol=matcht.regression_name,est&&(Array.lengtht.coeffs=1)with|Somename,true->name|Somename,false->col^name|None,_->colinletunit=Variable.get_unitst.responderinletname=Variable.to_short_stringt.responderinletcols=[]inletcols=(* Display R^2 is required *)ift.has_r_squarethenletr_square=create_colt(append_name(name^" R^2")~est:false)~f:(funregr->letnon_triv=Array.fold~init:false(R.coefficientsregr)~f:(funacccoeff->(acc||C.has_non_trivial_estimatecoeff~show_all_values:false~responder:t.responder))inifnon_trivthen([],To_string.float_opt_to_string(R.r_squareregr))elseifshow_all_valuesthen([`Dim],To_string.float_opt_to_string(R.r_squareregr))else([],""))inr_square::colselsecolsinList.rev(Array.foldit.coeffs~init:cols~f:(funiacccoeff->ifcoeff.Coeff.predictor=`One&&(notshow_overheads)thenaccelsebeginletmag=coeff.Coeff.magnitudein(* Display Estimates *)letest_col=create_colt(append_name(Variable.make_col_namet.respondercoeff.Coeff.predictor)~est:false)~f:(funregr->letest=(R.coefficientsregr).(i)inWarnings.check_for_long_running_benchmarks~resp:t.responder~pred:coeff.Coeff.predictor(C.estimateest);Display_units.to_string~show_all_valuesunitmag(C.estimateest))in(* Display confidence intervals *)ifcoeff.Coeff.has_cithenletest_ci_col=create_colt(append_name"95ci"~est:false)~f:(funregr->letest=(R.coefficientsregr).(i)inmatchC.ci95estwith|None->([],"")|Someci->(* Suppress the ci if the estimate has been suppressed. *)letnon_triv=C.has_non_trivial_estimateest~show_all_values:false~responder:t.responderinifnon_triv||show_all_valuesthenletattr,str=ifshow_absolute_cithenDisplay_units.to_ci_string~show_all_valuesunitmag(Analysis_result.Ci95.ci95_abs_errci~estimate:(C.estimateest))elseDisplay_units.to_ci_string~show_all_valuesDisplay_units.Percentagemag(Analysis_result.Ci95.ci95_rel_errci~estimate:(C.estimateest))inletattr=ifshow_all_valuesthen(`Dim::attr)elseattrin(attr,str)else([],""))inest_ci_col::est_col::accelseest_col::accend))endletmake_speed_and_percentage_columnsdisplay_configtbl=letshow_percentage=display_config.Display_config.show_percentageinletshow_speedup=display_config.Display_config.show_speedupinletshow_all_values=display_config.Display_config.show_all_valuesinifshow_percentage||show_speedupthenbegin(* To computer speedup and percentage, we need the Nanos-vs-Rubs regression as to be
present in the results. *)lettiming_key=Analysis_config.make_keyAnalysis_config.nanos_vs_runsinmatchInt.Table.findtbltiming_keywith|None->printf"Error: Estimating speedup/percentage requires Nanos-vs-Runs analysis.\n%!";[]|Someregr->letsmallest=Option.value_exnregr.Regr.coeffs.(0).Regr.Coeff.smallest~message:"Reading smallest Nanos-vs-Runs value"inletlargest=Option.value_exnregr.Regr.coeffs.(0).Regr.Coeff.largest~message:"Reading largest Nanos-vs-Runs value"inletget_coeffregr=C.estimate(R.coefficientsregr).(0)inletcols=[]inletcols=ifshow_speedupthenletcol=Ascii_table.Column.create~align:Right"Speedup"(funres->matchAnalysis_result.find_keyrestiming_keywith|None->"?"|Someregr->To_string.float_to_string(get_coeffregr/.smallest))incol::colselsecolsinletcols=ifshow_percentagethenletcol=Ascii_table.Column.create_attr~align:Right"Percentage"(funres->matchAnalysis_result.find_keyrestiming_keywith|None->([],"?")|Someregr->letdummy=Display_units.Magnitude.OneinDisplay_units.to_string~show_all_valuesDisplay_units.Percentagedummy(get_coeffregr/.largest))incol::colselsecolsincolsendelse[]letmake_columns_for_regressionsdisplay_configresults=lettbl=Int.Table.create()inletadd_to_tableregr=Regr.update~regr(Int.Table.find_or_addtbl(R.keyregr)~default:(fun()->Regr.createregr))inList.iterresults~f:(funresult->Array.iter(Analysis_result.regressionsresult)~f:(funregr->add_to_tableregr));letregressions=List.sort(Int.Table.to_alisttbl)~compare:(fun(a,_)(b,_)->compareab)inletshow_absolute_ci=display_config.Display_config.show_absolute_ciinletshow_all_values=display_config.Display_config.show_all_valuesinletshow_overheads=display_config.Display_config.show_overheadsinletcols=List.fold~init:[]regressions~f:(funacc(_key,data)->acc@Regr.make_columns~show_absolute_ci~show_all_values~show_overheadsdata)incols@(make_speed_and_percentage_columnsdisplay_configtbl)letmake_columnsdisplay_configresults=letcols=make_columns_for_regressionsdisplay_configresultsinletcols=ifdisplay_config.Display_config.show_samplesthenletsamples=Ascii_table.Column.create~align:Right"Runs @ Samples"(funres->sprintf"%d @ %d"(Analysis_result.largest_runres)(Analysis_result.sample_countres))insamples::colselsecolsinletcols=letname=Ascii_table.Column.create~align:Left"Name"(funres->Analysis_result.nameres)inname::colsincolsletdisplay?libname~display_configresults=ifdisplay_config.Display_config.show_output_as_sexpthenSimplified_benchmark.to_sexp?libnameresults|>Sexp.to_string|>print_endlineelsebeginletcols=make_columnsdisplay_configresultsinAscii_table.output~oc:stdout~limit_width_to:(Display_config.limit_width_todisplay_config)~bars:(if(Display_config.ascii_tabledisplay_config)then`Asciielse`Unicode)~display:(Display_config.displaydisplay_config)colsresults;Warnings.display();end