Last active
January 23, 2018 02:58
-
-
Save c-cube/0a0040855bdd0607de2770ba76d789d0 to your computer and use it in GitHub Desktop.
benchmark record vs object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)) | |
| )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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