Commit 52571dd3 authored by Maximilien Colange's avatar Maximilien Colange

Add a function to time another function.

parent b09d246f
...@@ -18,6 +18,7 @@ all-local: tiamo ...@@ -18,6 +18,7 @@ all-local: tiamo
tiamo: src/main.native tiamo: src/main.native
cp $(BUILDDIR)/$< tiamo cp $(BUILDDIR)/$< tiamo
src/main.native: src/ctime.o
src/main.native: src/timedAutomatonBuilder.o src/main.native: src/timedAutomatonBuilder.o
.ml.native: .ml.native:
......
...@@ -41,20 +41,21 @@ let _ = ...@@ -41,20 +41,21 @@ let _ =
flag ["c++";"noassert"] (ocaml_cxx_flags ["-DNDEBUG"]); flag ["c++";"noassert"] (ocaml_cxx_flags ["-DNDEBUG"]);
(* hard-coding the C file and utap library seems the easiest way (* hard-coding the C file and utap library seems the easiest way
* to avoid problems in object ordering at link time. * to avoid problems in object ordering at link time.
* Unfortunately, the dependency is not handled through ocamlbuild, * Unfortunately, the dependency is not handled through ocamlbuild,
* but in the Makefile directly. * but in the Makefile directly.
*) *)
let xml_flags = let xml_flags =
try try
Sys.getenv "XML_LINK_FLAGS" Sys.getenv "XML_LINK_FLAGS"
with Not_found -> "-lxml2" with Not_found -> "-lxml2"
in in
flag ["ocaml"; "link"; "native"] flag ["ocaml"; "link"; "native"]
(S[ P"src/timedAutomatonBuilder.o"; (S[ P"src/ctime.o";
A"-cclib"; A("-L"^(Pathname.pwd / "utap/src")); P"src/timedAutomatonBuilder.o";
A"-cclib"; A"-lutap"; A"-cclib"; A("-L"^(Pathname.pwd / "utap/src"));
A"-cclib"; A xml_flags A"-cclib"; A"-lutap";
A"-cclib"; A xml_flags
]); ]);
| _ -> () | _ -> ()
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
<*.c> or <*.cm{o,x}> or <main.native>: custom @OCAMLTAGS@ <*.c> or <*.cm{o,x}> or <main.native>: custom @OCAMLTAGS@
<main.native>: use_dynlink <main.native>: use_dynlink
<costs.ml>: pp(camlp4o pa_macro.cmo @TIAMO_MACROS@) <costs.ml>: pp(camlp4o pa_macro.cmo @TIAMO_MACROS@)
<timedAutomatonBuilder.c>: c++ <timedAutomatonBuilder.c> or <ctime.c>: c++
extern "C" {
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/callback.h>
}
#include <chrono>
extern "C" CAMLprim value
time_measure_function(value f)
{
CAMLparam1(f);
CAMLlocal1(res);
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
res = caml_callback(f, Val_unit);
end = std::chrono::system_clock::now();
std::chrono::seconds elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(end-start);
CAMLreturn(caml_callback2(*caml_named_value("cb_build_pair"), Val_long(elapsed_seconds.count()), res));
}
(**
* Executes a function and time it.
* The elapsed time is returned in seconds.
*)
external measure_function : (unit -> 'a) -> int * 'a = "time_measure_function";;
...@@ -820,7 +820,8 @@ struct ...@@ -820,7 +820,8 @@ struct
Printf.printf "Input automaton parsed, computing LU bounds\n"; Printf.printf "Input automaton parsed, computing LU bounds\n";
flush stdout; flush stdout;
build_lu ta; let (elapsed_seconds,_) = Time.measure_function (fun () -> build_lu ta) in
Printf.printf "Took %d seconds to compute LU bounds\n" elapsed_seconds;
ta ta
let make_ta tafile qfile = let make_ta tafile qfile =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment