1
(*pp camlp4o -I ../lib -I `ocamlfind query type-conv` pa_type_conv.cmo pa_bin_prot.cmo *)
9
TYPE_CONV_PATH "Mac_test"
11
(* Checks correct behavior for empty types *)
12
type empty with bin_io
15
(* Checks correct behavior for type signatures with variance annotations. *)
16
type +'a t with bin_io
19
module PolyInhTest = struct
20
type x = [ `X1 | `X2 ] with bin_io
21
type y = [ `Y1 | `Y2 ] with bin_io
22
type xy = [ x | `FOO | `Bar of int * float | y ] with bin_io
25
type tuple = float * string * int64
28
type 'a record = { a : int; b : 'a; c : 'b. 'b option }
31
type 'a singleton_record = { y : 'a }
34
type 'a sum = Foo | Bar of int | Bla of 'a * string
37
type 'a variant = [ `Foo | `Bar of int | `Bla of 'a * string ]
40
type 'a poly_app = (tuple * int singleton_record * 'a record) variant sum list
43
type 'a rec_t1 = RecFoo1 of 'a rec_t2
44
and 'a rec_t2 = RecFoo2 of 'a poly_app * 'a rec_t1 | RecNone
47
type 'a poly_id = 'a rec_t1
50
type el = float poly_id
56
let mb = 1024. *. 1024.
59
(* Allocate buffer (= bigstring) *)
60
let buf = create_buf 10000 in
62
(* Define array of dummy elements to be marshalled *)
64
let record = { a = 17; b = 2.78; c = None } in
65
let arg = (3.1, "foo", 42L), { y = 4321 }, record in
66
let variant = `Bla (arg, "fdsa") in
67
let sum = Bla (variant, "asdf") in
68
let poly_app = [ sum ] in
69
RecFoo1 (RecFoo2 (poly_app, RecFoo1 RecNone))
71
let x = Array.create 10 el in
76
let t1 = Unix.gettimeofday () in
78
ignore (bin_write_els buf ~pos:0 x)
80
let t2 = Unix.gettimeofday () in
81
let write_time = t2 -. t1 in
84
let t1 = Unix.gettimeofday () in
86
let pos_ref = ref 0 in
87
ignore (bin_read_els buf ~pos_ref)
89
let t2 = Unix.gettimeofday () in
90
let read_time = t2 -. t1 in
92
(* Write, read, and verify *)
93
let end_pos = bin_write_els buf ~pos:0 x in
94
let pos_ref = ref 0 in
95
let y = bin_read_els buf ~pos_ref in
96
assert (!pos_ref = end_pos && x = y);
100
let msg_size = float (n * end_pos) in
102
"msgs: %d msg length: %d\n\
103
write time: %.3fs write rate: %9.2f msgs/s write throughput: %.2f MB/s\n\
104
\ read time: %.3fs read rate: %9.2f msgs/s read throughput: %.2f MB/s\n%!"
106
write_time (f_n /. write_time) (msg_size /. write_time /. mb)
107
read_time (f_n /. read_time) (msg_size /. read_time /. mb)
111
with Read_error (err, pos) ->
112
eprintf "Uncaught exception: %s: %d\n%!" (ReadError.to_string err) pos