-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_codegen.ml
More file actions
49 lines (42 loc) · 1.52 KB
/
Copy pathbench_codegen.ml
File metadata and controls
49 lines (42 loc) · 1.52 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
(* SPDX-License-Identifier: MPL-2.0 *)
(* WASM codegen sweep.
Like the typecheck bench, we resolve+typecheck once outside the
timing loop so the measurement is purely codegen. *)
open Affinescript
let iterations = 80
let time_ms f =
let t0 = Unix.gettimeofday () in
let r = f () in
let t1 = Unix.gettimeofday () in
(1000.0 *. (t1 -. t0), r)
let prep src =
match (try Some (Parse_driver.parse_string ~file:"<bench>" src)
with _ -> None) with
| None -> None
| Some prog ->
let cfg = Module_loader.default_config () in
let loader = Module_loader.create cfg in
(match Resolve.resolve_program_with_loader prog loader with
| Error _ -> None
| Ok _ -> Some prog)
let bench_one (label, src) =
match prep src with
| None -> Printf.printf " codegen[%s]: prep failed, skipping\n%!" label
| Some prog ->
let elapsed, ok =
time_ms (fun () ->
let ok = ref 0 in
for _ = 1 to iterations do
match (try Codegen.generate_module prog with _ -> Error (Codegen.UnsupportedFeature "<bench raised>")) with
| Ok _ -> incr ok
| Error _ -> ()
done;
!ok)
in
let per_iter = if iterations > 0 then elapsed /. float_of_int iterations else 0.0 in
Printf.printf
" codegen[%s]: %d iters (%d ok), %.2fms total, %.3fms/iter\n%!"
label iterations ok elapsed per_iter
let run () =
print_endline "── bench: codegen (wasm) ──────────────────────";
List.iter bench_one Bench_fixtures.all