blob: ffd98ed0f4083953819aaf162528fbd3e7610849 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
(* TEST_BELOW
(* Blank lines added here to preserve locations. *)
*)
type a = { mutable a : int }
let alloc {a} b = a + b
let noalloc b {a} = b + a
let measure name f =
let a = {a = 1} in
let b = 2 in
let before = Gc.minor_words () in
let (_ : int) = f ~a ~b in
let after = Gc.minor_words () in
let alloc = int_of_float (after -. before) in
match alloc with
| 0 -> Printf.printf "%S doesn't allocate\n" name
| _ -> Printf.printf "%S allocates\n" name
let () =
measure "noalloc" (fun ~a ~b -> noalloc b a);
measure "alloc" (fun ~a ~b -> alloc a b)
let dont_warn_with_partial_match None x = x
(* TEST
flags = "-w +A-70";
setup-ocamlopt.byte-build-env;
ocamlopt.byte;
check-ocamlopt.byte-output;
run;
check-program-output;
*)
|