Skip to content

Instantly share code, notes, and snippets.

@yoshihiro503
Last active June 28, 2019 05:37
Show Gist options
  • Save yoshihiro503/9a95f2274f166fffdb73c6b4ddac4e58 to your computer and use it in GitHub Desktop.
Save yoshihiro503/9a95f2274f166fffdb73c6b4ddac4e58 to your computer and use it in GitHub Desktop.
erlangのモジュールをたくさん作るOCamlプログラム
let number_of_modules =
if Array.length Sys.argv <= 1 then 100
else Sys.argv.(1) |> int_of_string
let create_module_succ index =
Printf.sprintf {|
-module(mod_%d).
-export([f/1]).
-spec f(input_%n) -> ok.
f(input_%n) -> mod_%n:f(input_%d).
|} index index index (index - 1) (index - 1)
let create_module_zero =
Printf.sprintf {|
-module(mod_0).
-export([f/1]).
-spec f(input_0) -> ok.
f(input_0) -> ok.
|}
let create_module index =
if index = 0 then
create_module_zero
else
create_module_succ index
let open_file_with filename f =
let ch = open_out filename in
try
let y = f ch in
close_out ch;
y
with
e -> close_out ch;
raise e
let save_module index =
let filename = Printf.sprintf "mod_%d.erl" index in
prerr_endline (Printf.sprintf "file %s creating..." filename);
open_file_with filename (fun ch ->
output_string ch (create_module index))
let _ =
for i = 0 to number_of_modules-1 do
save_module i
done
@yoshihiro503
Copy link
Author

yoshihiro503 commented Jun 28, 2019

DialyzerとFialyzerの速度比較に使う例

#!/bin/sh
set -eu
FIALYZER=<PATH_TO_FIALYZER>
ocamlc create_erlang_modules.ml
./a.out 10000
erlc +debug_info *.erl
echo ==== DIALYZER ====
time dialyzer  --plt ~/.dialyzer_plt *.beam
echo ==== FIALYZER ====
time $FIALYZER  --plt ~/.dialyzer_plt *.beam
rm *.erl *.beam a.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment