-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ml
More file actions
64 lines (50 loc) · 1.31 KB
/
test.ml
File metadata and controls
64 lines (50 loc) · 1.31 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
open Prog
let env = [("input", 2021)]
let e =
LET (
"x", NUM 314,
LET (
"y", NUM 159,
IF (
ADD (VAR "input", NEG (NUM 2021)),
VAR "x",
VAR "y"
)
)
)
let ans = eval env e
(* makeshift helper function for checking execution times *)
let profile name cmd =
let t1 = Sys.time () in
let retval = Lazy.force cmd in
let t2 = Sys.time () in
let () = Printf.printf "%s: %f secs" name (t2 -. t1) in
let () = print_newline () in (* also flushes stdout *)
retval
let cmd = lazy (He.param_gen ())
let params = profile "param_gen" cmd
let cmd = lazy (He.key_gen params)
let sk = profile "key_gen" cmd
let cmd = lazy (He.get_evalkey sk)
let ek = profile "get_eval_key" cmd
let cmd = lazy (enc_env env sk)
let eenv = profile "enc_env" cmd
let cmd = lazy (enc_exp e sk)
let ee = profile "enc_exp" cmd
let cmd = lazy (eeval eenv ee ek)
let en = profile "eeval" cmd
let cmd = lazy (He.dec_val en sk)
let n = profile "dec_val" cmd
let cmd = lazy (He.delete_key sk)
let () = profile "delete_key" cmd
let cmd = lazy (He.delete_params params)
let () = profile "delete_params" cmd
(* decoding 16-bit integer *)
let res =
if n land (1 lsl 15) == 0 then n
else n - 0x10000
let () = Printf.printf
"\nresult = %d %s %d = answer\n"
res
(if res = ans then "=" else "!=")
ans