let time f = let start = Sys.time() in let _ = f () in Sys.time() -. start let rec bad_reverse l = (* O(length(l)^2 *) match l with [] -> [] | h :: t -> bad_reverse t @ [h] let reverse l = (* O(Length(l)) *) let rec aux l rl = match l with [] -> rl | h :: t -> aux t (h :: rl) in aux l [] let iota n = List.init n (fun x -> x) let l = iota 20000 let rec sum_list l = match l with [] -> 0 | h :: t -> (+) h (sum_list t) let sum_list_fold l = List.fold_right (+) l 0 (* time (fun () -> reverse1 l) *) (* let rec f_gen l = match l with [] -> a | h :: t -> op h (f_gen l) => List.fold_right let f_gen l = let rec aux acc l = match l with [] -> acc | h :: t -> aux t (op acc h) in aux a (List.rev l) => List.fold_left *)