Skip to content

Instantly share code, notes, and snippets.

@c-cube
Last active January 23, 2018 02:58
Show Gist options
  • Select an option

  • Save c-cube/0a0040855bdd0607de2770ba76d789d0 to your computer and use it in GitHub Desktop.

Select an option

Save c-cube/0a0040855bdd0607de2770ba76d789d0 to your computer and use it in GitHub Desktop.
benchmark record vs object
(executable
((name truc)
(libraries (benchmark))
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -color always))
(ocamlopt_flags (:standard -O3 -bin-annot
-unbox-closures -unbox-closures-factor 20))
))
let n_iter = 1_000_000
let obj = object
method do_it n = Sys.opaque_identity (n+42)
end
let f_obj obj x =
for _i = 1 to n_iter do
ignore (Sys.opaque_identity (obj#do_it x))
done
type r = {
do_it : int -> int;
}
let r = {
do_it = (fun n -> n+42);
}
let f_rec r x =
for _i = 1 to n_iter do
ignore (Sys.opaque_identity (r.do_it x))
done
let ()=
Benchmark.tabulate @@
Benchmark.throughputN 3 [
"obj", (f_obj obj), 10;
"rec", (f_rec r), 10;
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment