summaryrefslogtreecommitdiff
path: root/test/alloc.ml
blob: ea103e42af29a3989c0db1c35433cd6c7304835e (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
44
45
46
47
48
49
50
51
(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*             Damien Doligez, projet Para, INRIA Rocquencourt         *)
(*                                                                     *)
(*  Copyright 1996 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the Q Public License version 1.0.               *)
(*                                                                     *)
(***********************************************************************)

(* $Id$ *)

(* Random allocation test *)

(*
  Allocate arrays of strings, of random sizes in [0..1000[, and put them
  into an array of 32768.  Replace a randomly-selected array with a new
  random-length array.  Reiterate ad infinitum.
*)

let l = 32768;;
let m = 1000;;

let ar = Array.create l "";;

Random.init 1234;;

let compact_flag = ref false;;

let main () =
  while true do
    for i = 1 to 100000 do
      ar.(Random.int l) <- String.create (Random.int m);
    done;
    if !compact_flag then Gc.compact () else Gc.full_major ();
    print_newline ();
    Gc.print_stat stdout;
    flush stdout;
  done
;;

let argspecs = [
  "-c", Arg.Set compact_flag, "do heap compactions";
];;

Arg.parse argspecs (fun _ -> ()) "Usage: alloc [-c]";;

main ();;