File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ (* TEST *)
2
+
3
+ let [@ inline never] float_unboxing s f =
4
+ let x = Sys. opaque_identity (s +. 1. ) in
5
+ let mw1 = Gc. minor_words () in
6
+ let mw2 = Gc. minor_words () in
7
+ f x;
8
+ let mw3 = Gc. minor_words () in
9
+ Printf. printf " unbox: %.0f\n " ((mw3 -. mw2) -. (mw2 -. mw1))
10
+
11
+ let [@ inline never] lifetimes () =
12
+ let final = ref false in
13
+ let go () =
14
+ let r = ref 42 in
15
+ Gc. finalise (fun _ -> final := true ) r;
16
+ let f1 = ! final in
17
+ Gc. full_major () ;
18
+ let f2 = ! final in
19
+ ignore (Sys. opaque_identity r);
20
+ (f1, f2) in
21
+ let (f1, f2) = go () in
22
+ Gc. full_major () ;
23
+ let f3 = ! final in
24
+ Printf. printf " lifetime: %b %b %b\n " f1 f2 f3
25
+
26
+ let [@ inline never] dead_alloc a =
27
+ let mw1 = Gc. minor_words () in
28
+ let mw2 = Gc. minor_words () in
29
+ ignore (Sys. opaque_identity (a, a));
30
+ let mw3 = Gc. minor_words () in
31
+ Printf. printf " dead: %.0f\n " ((mw3 -. mw2) -. (mw2 -. mw1))
32
+
33
+
34
+ let () =
35
+ float_unboxing 50. (fun _ -> () );
36
+ lifetimes () ;
37
+ dead_alloc 10
38
+
Original file line number Diff line number Diff line change
1
+ unbox: 0
2
+ lifetime: false false true
3
+ dead: 3
You can’t perform that action at this time.
0 commit comments