(***********************************************************************)
(*
- Time-stamp: <Last modified on 2013-04-22 17:26:34 CEST by Kim Nguyen>
+ Time-stamp: <Last modified on 2013-04-22 18:48:48 CEST by Kim Nguyen>
*)
open Format
+let time f arg msg =
+ let t1 = Unix.gettimeofday () in
+ let r = f arg in
+ let t2 = Unix.gettimeofday () in
+ let time = (t2 -. t1) *. 1000. in
+ if !Options.stats then fprintf err_formatter "@[STATS: %s: %fms@]@." msg time;
+ r
+
+
let main () =
let () = Options.parse () in
let doc =
let fd = open_in !Options.input_file in
- let d = Naive_tree.load_xml_file fd in
+ let d = time Naive_tree.load_xml_file fd "parsing xml document" in
close_in fd; d
in
let query =
- Xpath.Parser.parse (Ulexing.from_latin1_string !Options.query)
+ time
+ Xpath.Parser.parse
+ (Ulexing.from_latin1_string !Options.query)
+ "parsing XPath query"
in
let auto =
- Xpath.Compile.path query
+ time Xpath.Compile.path query "compiling XPath query"
in
let output =
match !Options.output_file with
Ata.print err_formatter auto;
fprintf err_formatter "@]@]@.";
end;
+
let module Naive = Eval.Make(Naive_tree) in
- let t1 = Unix.gettimeofday() in
- let results = Naive.eval auto doc (Naive_tree.root doc) in
- let teval = (Unix.gettimeofday () -. t1) *. 1000. in
- let t1 = Unix.gettimeofday () in
+ let results =
+ time (Naive.eval auto doc) (Naive_tree.root doc) "evaluating query"
+ in
+ time (fun () ->
output_string output "<xml_result>\n";
if !Options.count then begin
output_string output (string_of_int (List.length results));
output_char output '\n'
) results;
output_string output "</xml_result>\n";
- let tprint = (Unix.gettimeofday () -. t1) *. 1000. in
flush output;
- if output != stdout then close_out output;
- if !Options.stats then begin
- fprintf err_formatter "@[STATS: evaluation time: %fms@]@." teval;
- fprintf err_formatter "@[STATS: serialization time: %fms@]@." tprint
- end
+ if output != stdout then close_out output
+
+) () "serializing results"
let () =