-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: simplify gen_synthetic further
Signed-off-by: Javier Chávarri <javier.chavarri@gmail.com>
- Loading branch information
Showing
2 changed files
with
14 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |