Skip to content

Instantly share code, notes, and snippets.

@kayceesrk
Created December 3, 2021 10:07
Show Gist options
  • Save kayceesrk/bf2c5b373da15ac747927924e4b27389 to your computer and use it in GitHub Desktop.
Save kayceesrk/bf2c5b373da15ac747927924e4b27389 to your computer and use it in GitHub Desktop.
type tree = Leaf of int | Node of tree * tree
let gensym = ref 0
let rec build_tree n =
if n <= 0
then (incr gensym; Leaf !gensym)
else Node(build_tree (n-1), build_tree (n-1))
let test n repet =
let s = Marshal.to_string (build_tree n) [] in
let start = Sys.time() in
for _i = 1 to repet do
ignore (Marshal.from_string s 0)
done;
let stop = Sys.time() in
Printf.printf "%d %.1e\n" n ((stop -. start) /. float_of_int repet)
let _ =
let n = int_of_string Sys.argv.(1) in
let repet = if n < 26 then 1 lsl (26 - n) else 1 in
test n repet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment