%%%------------------------------------------------------------------- %%% File : bit_bench.erl %%% Author : Per Gustafsson %%% Description : %%% %%% Created : 27 Feb 2006 by Per Gustafsson %%%------------------------------------------------------------------- -module(bit_bench). -export([run/0,find_diff/2]). -define(BENCHES,["drop3","five11","huffman","uudecode","uuencode"]). -define(LANGS, [erlang,haskell,ocaml]). compile_cmd(BenchName, ocaml) -> "touch " ++ BenchName ++ ".ml; " ++ "ocamlopt -noassert -unsafe -ccopt -O3 " ++ BenchName ++ ".ml -o " ++ BenchName ++ "ocaml.run"; compile_cmd(BenchName, java) -> "touch " ++ BenchName ++ ".java; " ++ "gcj -O3 --main=" ++ BenchName ++ " -o " ++ BenchName ++ "java.run " ++ BenchName ++ ".java"; compile_cmd(BenchName, erlang) -> "/home/pergu/otp/bin/erlc +native +\"{hipe,[bincomp]}\" " ++ BenchName ++ ".erl"; compile_cmd(BenchName, haskell) -> "touch " ++ BenchName ++ ".hs; " ++ "ghc -O3 -optc-O3 -fglasgow-exts -fexcess-precision -o " ++ BenchName ++ "haskell.run " ++ BenchName ++ ".hs"; compile_cmd(BenchName, c) -> "touch " ++ BenchName ++ ".c; " ++ "gcc -O3 -o " ++ BenchName ++ "c.run " ++ BenchName ++ ".c". run_cmd(BenchName,erlang) -> "/home/pergu/otp/bin/erl -noshell -pa -run " ++ BenchName ++ " test"; run_cmd(BenchName,Lang) -> BenchName ++ atom_to_list(Lang) ++ ".run". run() -> format_call(["Benchmark"|[atom_to_list(X) || X<-?LANGS]]), run_benches(?BENCHES). run_benches([BenchName|Rest]) -> format_call([BenchName|run_bench(BenchName, ?LANGS)]), run_benches(Rest); run_benches([]) -> []. run_bench(BenchName, [Lang|Rest]) -> CCmd = compile_cmd(BenchName, Lang), os:cmd(CCmd), RCmd = run_cmd(BenchName, Lang), [process_res(os:cmd(RCmd ++ " testdata." ++ BenchName))| run_bench(BenchName, Rest)]; run_bench(_,[]) -> []. format_call([L]) -> io:format("~.10s \\\\\n",[L]); format_call([H|T]) -> io:format("~.10s & ",[H]), format_call(T). process_res(String) -> hd(io_lib:format("~.3f",[list_to_float(String)])). find_diff(F1,F2) -> {ok,B1} = file:read_file(F1), {ok,B2} = file:read_file(F2), do_diff(B1,B2,1). do_diff(<>,<>,N) -> do_diff(Rest1,Rest2,N+1); do_diff(<>,<>,N) -> {X,Y,N}; do_diff(<<>>,<<>>,_N) -> ok.