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
tiamo: src/main.native
cp $(BUILDDIR)/$< tiamo
src/main.native: src/ctime.o
src/main.native: src/timedAutomatonBuilder.o
.ml.native:
......
......@@ -51,7 +51,8 @@ let _ =
with Not_found -> "-lxml2"
in
flag ["ocaml"; "link"; "native"]
(S[ P"src/timedAutomatonBuilder.o";
(S[ P"src/ctime.o";
P"src/timedAutomatonBuilder.o";
A"-cclib"; A("-L"^(Pathname.pwd / "utap/src"));
A"-cclib"; A"-lutap";
A"-cclib"; A xml_flags
......
......@@ -2,4 +2,4 @@
<*.c> or <*.cm{o,x}> or <main.native>: custom @OCAMLTAGS@
<main.native>: use_dynlink
<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
Printf.printf "Input automaton parsed, computing LU bounds\n";
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
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