X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Ftatoo.ml;h=2c3206245cee5f9f6b7cf101e58218f43c5ffc5b;hp=6dc66efe22226ce38d9a775f9f2b7c4534840faa;hb=318ebb395fe3665046b76cf4de6cf8166b94d4cc;hpb=ebe172413cade8d324561a0279b9b8017b9a2fc0 diff --git a/src/tatoo.ml b/src/tatoo.ml index 6dc66ef..2c32062 100644 --- a/src/tatoo.ml +++ b/src/tatoo.ml @@ -14,23 +14,35 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) 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 @@ -43,11 +55,12 @@ let main () = 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 "\n"; if !Options.count then begin output_string output (string_of_int (List.length results)); @@ -58,13 +71,10 @@ let main () = output_char output '\n' ) results; output_string output "\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 () =