(* Test method dispatch vs. function dispatch vs. closure dispatch *) let f x = x + 100 let call_f () = f 1 let o = object method f_o x = x + 100 end let call_o () = o#f_o 1 let f_c () x = x + 100 let f_c' = f_c () let call_fc () = f_c' 1 let o_c = object method f_oc () x = x + 100 end let f_oc' = o_c#f_oc () let call_foc () = f_oc' 1 open Benchmark let () = let results = latencyN ~repeat:5 1100000000L (* let results = throughputN ~repeat:5 1 *) [("function", call_f, ()); ("method", call_o, ()); ("closure", call_fc, ()); ("obj. closure", call_foc, ())] in tabulate results (* ocamlopt -o gray.com -inline 0 -I benchmark unix.cmxa benchmark.cmxa gray.ml ocamlc -o gray.exe -inline 0 -I benchmark unix.cma benchmark.cma gray.ml *)