[Infer][Perf] Emit messages using the asymptotic Bachmann–Landau notation, aka Big O notation

Reviewed By: mbouaziz

Differential Revision: D13042865

fbshipit-source-id: bf8e40e58
master
Martino Luca 6 years ago committed by Facebook Github Bot
parent ce5d3e469f
commit 32f448a6f0

@ -150,7 +150,7 @@ let issue_of_cost cost_info ~delta ~prev_cost ~curr_cost =
CostDomain.BasicCost.pp_degree cost_polynomial
else ()
in
Format.asprintf "Complexity %a from %a to %a.%a" pp_delta delta
Format.asprintf "Complexity of this function has %a from %a to %a.%a" pp_delta delta
CostDomain.BasicCost.pp_degree_hum prev_cost CostDomain.BasicCost.pp_degree_hum curr_cost
pp_raw_cost curr_cost
in

@ -314,7 +314,18 @@ module MakePolynomial (S : NonNegativeSymbol) = struct
fun p eval_sym -> match subst p eval_sym with p -> NonTop p | exception ReturnTop -> Top
let rec degree {terms} : int = M.fold (fun _ p acc -> max acc (degree p + 1)) terms 0
(** Emit a pair (d,t) where d is the degree of the polynomial and t is the first term with such degree *)
let rec degree_with_term {terms} =
M.fold
(fun t p acc ->
let d, p' = degree_with_term p in
max acc (d + 1, mult_symb p' t) )
terms (0, one)
let degree p = fst (degree_with_term p)
let degree_term p = snd (degree_with_term p)
let pp : F.formatter -> t -> unit =
let add_symb s (((last_s, last_occ) as last), others) =
@ -423,20 +434,9 @@ module NonNegativePolynomial = struct
match p with
| Top ->
Format.pp_print_string fmt "Top"
| NonTop p -> (
match NonNegativeNonTopPolynomial.degree p with
| 0 ->
Format.pp_print_string fmt "constant"
| 1 ->
Format.pp_print_string fmt "linear"
| 2 ->
Format.pp_print_string fmt "quadratic"
| 3 ->
Format.pp_print_string fmt "cubic"
| 4 ->
Format.pp_print_string fmt "quartic"
| d ->
Format.fprintf fmt "O(N^%d)" d )
| NonTop p ->
Format.fprintf fmt "O(%a)" NonNegativeNonTopPolynomial.pp
(NonNegativeNonTopPolynomial.degree_term p)
let encode astate = Marshal.to_string astate [] |> B64.encode

Loading…
Cancel
Save