Skip to content

Commit

Permalink
benchmark: simplify gen_synthetic further
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
  • Loading branch information
jchavarri committed Feb 28, 2023
1 parent 7de1cbd commit a51c384
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:

- name: Create synthetic benchmark
working-directory: bench
run: opam exec -- ../_boot/dune.exe exec ./gen_synthetic.exe -- -n 6 synthetic
run: opam exec -- ../_boot/dune.exe exec ./gen_synthetic.exe -- -n 2000 synthetic

- name: Run synthetic benchmark
working-directory: bench/synthetic
Expand Down
97 changes: 13 additions & 84 deletions bench/gen_synthetic.ml
Original file line number Diff line number Diff line change
@@ -1,104 +1,33 @@
open Printf

let dir_rows = ref 1

let dir_cols = ref 1

let mod_rows = ref 1

let mod_cols = ref 1

let comment_size = ref 5000

let count n = Array.to_list (Array.init n (fun k -> k + 1))

let write_modules basedir dir_row dir_col =
for row = 1 to !mod_rows do
for col = 1 to !mod_cols do
let deps =
if row = 1 then
if dir_row = 1 then []
else
List.flatten
(List.map
(fun k ->
List.map
(fun j ->
sprintf "M_%d_%d_%d_%d.f()" (dir_row - 1) j !mod_rows k)
(count !dir_cols))
(count !mod_cols))
else
List.map
(fun k -> sprintf "M_%d_%d_%d_%d.f()" dir_row dir_col (row - 1) k)
(count !mod_cols)
in

let deps = List.rev ("()" :: List.rev deps) in

let str_deps = String.concat ";\n " deps in
let comment = String.make !comment_size 'X' in
let mod_text = sprintf "(* %s *)\nlet f() =\n %s\n" comment str_deps in
let modname =
sprintf "%s/m_%d_%d_%d_%d" basedir dir_row dir_col row col
in
let f = open_out (sprintf "%s.ml" modname) in
output_string f mod_text;
close_out f;
let f = open_out (sprintf "%s.mli" modname) in
output_string f "val f : unit -> unit ";
close_out f
done
done;
let f = open_out (sprintf "%s/main.ml" basedir) in
let modname =
sprintf "Test.M_%d_%d_%d_%d" dir_row dir_col !mod_rows !mod_cols
in
let main = sprintf "let () = %s.f()" modname in
output_string f main;
close_out f
let write_modules basedir num_modules =
for current_mod = 1 to num_modules do
let modname = sprintf "%s/m_%d" basedir current_mod in
let f = open_out (sprintf "%s.ml" modname) in
close_out f
done

let dune =
{|
let dune = {|
(library
(name test)
(modules :standard \ main))

(executable
(name main)
(libraries test)
(modules main))
(name test))
|}

let write basedir =
let () = Unix.mkdir basedir 0o777 in
let f = open_out (Filename.concat basedir "dune") in
output_string f dune;
let () = close_out f in

for row = 1 to !dir_rows do
for col = 1 to !dir_cols do
write_modules basedir row col
done
done
write_modules basedir

let () =
let basedir = ref "." in
let num_modules = ref 0 in
Arg.parse
[ ( "-n"
, Arg.Int
(fun n ->
dir_rows := n;
dir_cols := n;
mod_rows := n;
mod_cols := n)
, "<n> set all of -dir-rows, -dir-cols, -mod-rows, -mod-cols to the \
same value" )
; ("-row", Arg.Int (fun n -> dir_rows := n), "<n> set row")
; ("-col", Arg.Int (fun n -> dir_cols := n), "<n> set col")
; ("-mrow", Arg.Int (fun n -> mod_rows := n), "<n> set mod-row")
; ("-mcol", Arg.Int (fun n -> mod_cols := n), "<n> set mod-col")
, Arg.Int (fun n -> num_modules := n)
, "<n> number of modules to include in the synthetic library" )
]
(fun d -> basedir := d)
(sprintf "usage: %s [basedir]" (Filename.basename Sys.argv.(0)));

write !basedir
write !basedir !num_modules

0 comments on commit a51c384

Please sign in to comment.