Skip to content

Commit 60768c9

Browse files
committed
Output benchmark results as JSON
1 parent 1ce3da7 commit 60768c9

File tree

5 files changed

+50
-27
lines changed

5 files changed

+50
-27
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ jobs:
9090
ocaml_compiler: ocaml-variants.5.2.0+options,ocaml-option-static
9191
upload_binaries: true
9292
upload_libs: true
93-
# Build the playground compiler on the fastest runner
93+
# Build the playground compiler and run the benchmarks on the fastest runner
9494
build_playground: true
95+
benchmarks: true
9596
- os: buildjet-2vcpu-ubuntu-2204-arm # ARM
9697
ocaml_compiler: ocaml-variants.5.2.0+options,ocaml-option-static
9798
upload_binaries: true
@@ -320,6 +321,14 @@ jobs:
320321
if: runner.os != 'Windows'
321322
run: make -C tests/gentype_tests/typescript-react-example clean test
322323

324+
- name: Build playground compiler
325+
if: matrix.benchmarks
326+
run: |
327+
opam exec -- node packages/playground-bundling/scripts/generate_cmijs.js
328+
opam exec -- dune build --profile browser
329+
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js
330+
331+
323332
- name: Build playground compiler
324333
if: matrix.build_playground
325334
run: |

dune-project

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
(and
2525
:with-test
2626
(= 0.26.2)))
27+
(yojson
28+
(and
29+
:with-test
30+
(= 2.2.2)))
2731
(ocaml-lsp-server
2832
(and
2933
:with-dev-setup

rescript.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues"
99
depends: [
1010
"ocaml" {>= "4.10"}
1111
"ocamlformat" {with-test & = "0.26.2"}
12+
"yojson" {with-test & = "2.2.2"}
1213
"ocaml-lsp-server" {with-dev-setup & = "1.19.0"}
1314
"cppo" {= "1.6.9"}
1415
"js_of_ocaml" {= "5.8.1"}

tests/syntax_benchmarks/Benchmark.ml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module Benchmark : sig
7979

8080
val make : name:string -> f:(t -> unit) -> unit -> t
8181
val launch : t -> unit
82-
val report : t -> unit
82+
val report : t -> Yojson.t list
8383
end = struct
8484
type t = {
8585
name: string;
@@ -98,23 +98,26 @@ end = struct
9898
}
9999

100100
let report b =
101-
print_endline (Format.sprintf "Benchmark: %s" b.name);
102-
print_endline (Format.sprintf "Nbr of iterations: %d" b.n);
103-
print_endline
104-
(Format.sprintf "Benchmark ran during: %fms" (Time.print b.duration));
105-
print_endline
106-
(Format.sprintf "Avg time/op: %fms"
107-
(Time.print b.duration /. float_of_int b.n));
108-
print_endline
109-
(Format.sprintf "Allocs/op: %d"
110-
(int_of_float (b.net_allocs /. float_of_int b.n)));
111-
print_endline
112-
(Format.sprintf "B/op: %d"
113-
(int_of_float (b.net_bytes /. float_of_int b.n)));
114-
115-
(* return (float64(r.Bytes) * float64(r.N) / 1e6) / r.T.Seconds() *)
116-
print_newline ();
117-
()
101+
[
102+
`Assoc
103+
[
104+
("name", `String (Format.sprintf "%s - avg. time" b.name));
105+
("unit", `String "ms");
106+
("value", `Float (Time.print b.duration /. float_of_int b.n));
107+
];
108+
`Assoc
109+
[
110+
("name", `String (Format.sprintf "%s - allocations" b.name));
111+
("unit", `String "");
112+
("value", `Int (int_of_float (b.net_allocs /. float_of_int b.n)));
113+
];
114+
`Assoc
115+
[
116+
("name", `String (Format.sprintf "%s - bytes allocated" b.name));
117+
("unit", `String "");
118+
("value", `Int (int_of_float (b.net_bytes /. float_of_int b.n)));
119+
];
120+
]
118121

119122
let make ~name ~f () =
120123
{
@@ -221,13 +224,19 @@ end = struct
221224
Benchmark.report b
222225

223226
let run () =
224-
benchmark "RedBlackTree.res" Parse;
225-
benchmark "RedBlackTree.res" Print;
226-
benchmark "RedBlackTreeNoComments.res" Print;
227-
benchmark "Napkinscript.res" Parse;
228-
benchmark "Napkinscript.res" Print;
229-
benchmark "HeroGraphic.res" Parse;
230-
benchmark "HeroGraphic.res" Print
227+
let results =
228+
List.flatten
229+
[
230+
benchmark "RedBlackTree.res" Parse;
231+
benchmark "RedBlackTree.res" Print;
232+
benchmark "RedBlackTreeNoComments.res" Print;
233+
benchmark "Napkinscript.res" Parse;
234+
benchmark "Napkinscript.res" Print;
235+
benchmark "HeroGraphic.res" Parse;
236+
benchmark "HeroGraphic.res" Print;
237+
]
238+
in
239+
print_endline (Yojson.pretty_to_string (`List results))
231240
end
232241

233242
let () = Benchmarks.run ()

tests/syntax_benchmarks/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
(foreign_stubs
2323
(language c)
2424
(names time))
25-
(libraries syntax))
25+
(libraries syntax yojson))
2626

2727
(data_only_dirs data)

0 commit comments

Comments
 (0)