(* You need the Benchmark module (http://www.bagley.org/~doug/ocaml/benchmark/). *) let map' f l = (* tail recursive version of map *) let rec aux acc = function | [] -> List.rev acc | hd :: tl -> aux (f hd :: acc) tl in aux [] l let map2 f l = (* Crazy way... *) Array.to_list(Array.map f (Array.of_list l)) let () = let f x = succ x in (* simple fun, so its cost should be unimportant *) let bench n = let l = Array.to_list (Array.init n (fun x -> x)) in Printf.printf ">>> LIST LENGTH = %i\n" n; let res = Benchmark.throughputN 20 [("List.map", List.map f, l); ("tail_rec", map' f, l); ("crazy", map2 f, l) ] in Benchmark.tabulate res in bench 100; bench 1000; bench 10_000; bench 100_000; bench 400_000