From 9522266372edb18327f96b21213b4efc3798ee98 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Wed, 13 Mar 2013 21:53:44 +0100 Subject: [PATCH] Make the program report query execution time and query serialization time. --- src/main.ml | 9 +++++++-- tools/XPathEval.java | 6 ++++++ tools/gen_test.sh | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.ml b/src/main.ml index 9a5fd69..d6a1986 100644 --- a/src/main.ml +++ b/src/main.ml @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) let doc = @@ -37,11 +37,16 @@ let () = fprintf err_formatter "Automata: %a\n%!" Auto.Ata.print auto; fprintf err_formatter "Evaluating automaton:\n%!"; let module Naive = Auto.Eval.Make(Tree.Naive) in + let t1 = Unix.gettimeofday() in let results = Naive.eval auto doc (Tree.Naive.root doc) in + let teval = (Unix.gettimeofday () -. t1) *. 1000. in + let t1 = Unix.gettimeofday () in output_string stdout "\n"; List.iter (fun n -> Tree.Naive.print_xml stdout doc n; output_char stdout '\n' ) results; output_string stdout "\n"; - flush stdout + let tprint = (Unix.gettimeofday () -. t1) *. 1000. in + flush stdout; + fprintf err_formatter "evaluation time: %fms\nserialization time: %fms\n%!" teval tprint diff --git a/tools/XPathEval.java b/tools/XPathEval.java index 436ba7a..d7dc54b 100644 --- a/tools/XPathEval.java +++ b/tools/XPathEval.java @@ -15,10 +15,13 @@ public class XPathEval { XPath xpath = XPathFactory.newInstance().newXPath(); String expression = args[1]; InputSource inputSource = new InputSource(args[0]); + long startTime = System.nanoTime(); NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); + long evalTime = (System.nanoTime() - startTime) / 1000000; Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StreamResult o = new StreamResult(System.out); + startTime = System.nanoTime(); System.out.println(""); for(int i = 0; i < nodes.getLength(); i++){ Node n = nodes.item(i); @@ -33,6 +36,9 @@ public class XPathEval { System.out.println(); }; System.out.println(""); + long printTime = (System.nanoTime() - startTime) / 1000000; + System.err.println("evaluation time: " + evalTime + "ms"); + System.err.println("serialization time: " + printTime + "ms"); } catch (XPathException e) { System.out.println (e.getCause()); } catch (Exception e) { diff --git a/tools/gen_test.sh b/tools/gen_test.sh index b55a701..1c9ce12 100755 --- a/tools/gen_test.sh +++ b/tools/gen_test.sh @@ -21,5 +21,5 @@ mkdir -p "$RESULTS" cat "$QUERIES" | grep -v '^#' | while read qname q do echo "Computing $q" - java -cp _build/tools XPathEval "$FILE" "$q" > "$RESULTS"/"$qname".xml + java -cp _build/tools XPathEval "$FILE" "$q" > "$RESULTS"/"$qname".xml 2> "$RESULTS"/"$qname".log done -- 2.17.1