Merge commit 'ocaml3102'
[ocaml.git] / test / alloc.ml
blobea103e42af29a3989c0db1c35433cd6c7304835e
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Damien Doligez, projet Para, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 (* $Id$ *)
15 (* Random allocation test *)
18 Allocate arrays of strings, of random sizes in [0..1000[, and put them
19 into an array of 32768. Replace a randomly-selected array with a new
20 random-length array. Reiterate ad infinitum.
23 let l = 32768;;
24 let m = 1000;;
26 let ar = Array.create l "";;
28 Random.init 1234;;
30 let compact_flag = ref false;;
32 let main () =
33 while true do
34 for i = 1 to 100000 do
35 ar.(Random.int l) <- String.create (Random.int m);
36 done;
37 if !compact_flag then Gc.compact () else Gc.full_major ();
38 print_newline ();
39 Gc.print_stat stdout;
40 flush stdout;
41 done
44 let argspecs = [
45 "-c", Arg.Set compact_flag, "do heap compactions";
46 ];;
48 Arg.parse argspecs (fun _ -> ()) "Usage: alloc [-c]";;
50 main ();;