Skip to content

Commit ca61a19

Browse files
committed
Bench: add wasm support
1 parent d64f79d commit ca61a19

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

benchmarks/common.ml

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ module Spec : sig
149149

150150
val js_of_ocaml_js_string : t
151151

152+
val wasm_of_ocaml : t
153+
152154
val byte_unsafe : t
153155

154156
val opt_unsafe : t
@@ -214,6 +216,8 @@ end = struct
214216

215217
let js_of_ocaml_js_string = create "jsstring" ".js"
216218

219+
let wasm_of_ocaml = create "wasm_of_ocaml" ".js"
220+
217221
let byte_unsafe = create "unsafe/byte" ""
218222

219223
let opt_unsafe = create "unsafe/opt" ""

benchmarks/run.ml

+25-1
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,19 @@ let _ =
253253
| `Cps -> "--effects=cps"
254254
| `Double_translation -> "--effects=double-translation"))
255255
in
256+
let compile_wasmoo ?(effects = `None) opts =
257+
compile
258+
(Format.sprintf
259+
"wasm_of_ocaml -q %s %s"
260+
opts
261+
(match effects with
262+
| `None -> ""
263+
| `Cps -> "--effects=cps"))
264+
in
256265
Format.eprintf "Compile@.";
257266
compile "ocamlc" src Spec.ml code Spec.byte;
258267
compile "ocamlopt" src Spec.ml code Spec.opt;
268+
compile_wasmoo "" code Spec.byte code Spec.wasm_of_ocaml;
259269
compile_jsoo "" code Spec.byte code Spec.js_of_ocaml;
260270
compile_jsoo "--opt=3" code Spec.byte code Spec.js_of_ocaml_o3;
261271
compile_jsoo "--enable=use-js-string" code Spec.byte code Spec.js_of_ocaml_js_string;
@@ -278,6 +288,7 @@ let _ =
278288
ml_size param src Spec.ml sizes Spec.ml;
279289
file_size param code Spec.byte sizes Spec.byte;
280290
file_size param code Spec.js_of_ocaml sizes (Spec.sub_spec Spec.js_of_ocaml "full");
291+
file_size param code Spec.wasm_of_ocaml sizes (Spec.sub_spec Spec.wasm_of_ocaml "full");
281292
compr_file_size
282293
param
283294
code
@@ -296,6 +307,12 @@ let _ =
296307
Spec.js_of_ocaml_effects_double_translation
297308
sizes
298309
(Spec.sub_spec Spec.js_of_ocaml_effects_double_translation "gzipped");
310+
compr_file_size
311+
param
312+
code
313+
Spec.wasm_of_ocaml
314+
sizes
315+
(Spec.sub_spec Spec.wasm_of_ocaml "gzipped");
299316
bzip2_file_size
300317
param
301318
code
@@ -314,6 +331,12 @@ let _ =
314331
Spec.js_of_ocaml
315332
sizes
316333
(Spec.sub_spec Spec.js_of_ocaml "bzip2");
334+
bzip2_file_size
335+
param
336+
code
337+
Spec.wasm_of_ocaml
338+
sizes
339+
(Spec.sub_spec Spec.wasm_of_ocaml "bzip2");
317340
runtime_size
318341
param
319342
code
@@ -354,6 +377,7 @@ let _ =
354377
; Some Spec.js_of_ocaml_call
355378
; Some Spec.js_of_ocaml_effects_cps
356379
; Some Spec.js_of_ocaml_effects_double_translation
380+
; Some Spec.wasm_of_ocaml
357381
] )
358382
else if effects
359383
then
@@ -368,7 +392,7 @@ let _ =
368392
( (match interpreters with
369393
| i :: _ -> [ i ]
370394
| [] -> [])
371-
, [ Some Spec.js_of_ocaml ] )
395+
, [ Some Spec.js_of_ocaml; Some Spec.wasm_of_ocaml ] )
372396
in
373397
List.iter compilers ~f:(fun (comp, dir) ->
374398
measure param src (Filename.concat times dir) Spec.js comp;

compiler/bin-wasm_of_ocaml/compile.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ let run
463463
in
464464
if times () then Format.eprintf " parsing: %a@." Timer.print t1;
465465
Fs.with_intermediate_file
466-
(Filename.temp_file (Filename.chop_extension output_file) ".wat")
466+
(Filename.temp_file
467+
(Filename.basename (Filename.chop_extension output_file))
468+
".wat")
467469
@@ fun wat_file ->
468470
let dir = Filename.chop_extension output_file ^ ".assets" in
469471
Link.gen_dir dir

0 commit comments

Comments
 (0)