Add -r <n> option to repeat the query execution n times.
authorKim Nguyễn <kn@lri.fr>
Fri, 20 Apr 2012 13:31:44 +0000 (15:31 +0200)
committerKim Nguyễn <kn@lri.fr>
Fri, 20 Apr 2012 13:31:44 +0000 (15:31 +0200)
src/main.ml
src/options.ml
src/options.mli

index 100d0e4..48f2e46 100644 (file)
@@ -17,12 +17,12 @@ let tuned_gc = { default_gc with
   Gc.major_heap_increment = 8*1024*1024;
   Gc.max_overhead = 1000000;
   Gc.space_overhead = 100;
-              }
+}
 
 let mk_runtime run auto doc arg count print outfile =
   fun () ->
     if !Options.do_perf then start_perf ();
-    let r = time ~count:1 ~msg:"Execution time" (run auto doc) arg in
+    let r = time ~count:!Options.repeat ~msg:"Execution time" (run auto doc) arg in
     if !Options.do_perf then stop_perf ();
     Logger.print Format.err_formatter "Number of results: %i@\n" (count r);
     match outfile with
@@ -31,7 +31,6 @@ let mk_runtime run auto doc arg count print outfile =
        time ~count:1 ~msg:"Serialization time" (print file doc) r
 ;;
 
-
 let main v query_string output =
   Tag.init (Tree.tag_operations v);
   let query =
@@ -39,7 +38,7 @@ let main v query_string output =
   in
   if !Options.verbose then begin
     Logger.print Format.err_formatter "Parsed query:@\n%a@\n"
-    XPath.Ast.print query;
+      XPath.Ast.print query;
   end;
   let auto, bu_info =
     time ~msg:"Compiling query" Compile.compile query
@@ -49,34 +48,34 @@ let main v query_string output =
   Gc.compact();
   Gc.set (tuned_gc);
   let runtime =
-  match !Options.bottom_up, bu_info with
+    match !Options.bottom_up, bu_info with
 
     | true, Some [ (query, pattern) ] ->
       if !Options.count_only then
-       let module R = ResJIT.Count in
-       let module M = Runtime.Make(R) in
-       mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize None
+        let module R = ResJIT.Count in
+        let module M = Runtime.Make(R) in
+        mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize None
       else
-       let module R = ResJIT.Mat in
-       let module M = Runtime.Make(R) in
-       mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file
+        let module R = ResJIT.Mat in
+        let module M = Runtime.Make(R) in
+        mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file
 
     | _ ->
-       (* run the query top_down *)
+      (* run the query top_down *)
 
       if !Options.bottom_up then
-       Logger.print Format.err_formatter "Cannot run the query in bottom-up mode, using top-down evaluator@\n@?";
+        Logger.print Format.err_formatter "Cannot run the query in bottom-up mode, using top-down evaluator@\n@?";
       if !Options.count_only then
-       let module R = ResJIT.Count in
-       let module M = Runtime.Make(R) in
-       if !Options.twopass then
-         mk_runtime M.twopass_top_down_run auto v Tree.root R.NS.length R.NS.serialize None
-       else
-         mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize None
+        let module R = ResJIT.Count in
+        let module M = Runtime.Make(R) in
+        if !Options.twopass then
+          mk_runtime M.twopass_top_down_run auto v Tree.root R.NS.length R.NS.serialize None
+        else
+          mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize None
       else
-       let module R = ResJIT.Mat in
-       let module M = Runtime.Make(R) in
-       mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file
+        let module R = ResJIT.Mat in
+        let module M = Runtime.Make(R) in
+        mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file
   in
   runtime ()
 ;;
@@ -89,9 +88,9 @@ let _ =
 
     let document =
       if Filename.check_suffix !Options.input_file ".g.bin" ||
-       Filename.check_suffix !Options.input_file ".g"
+        Filename.check_suffix !Options.input_file ".g"
       then
-       let is_index = Filename.check_suffix !Options.input_file ".g.bin" in
+        let is_index = Filename.check_suffix !Options.input_file ".g.bin" in
        let g =
          if is_index then
            time ~msg:"Loading grammar" (Grammar2.load) !Options.input_file
@@ -102,7 +101,7 @@ let _ =
            g
        in
        begin
-      (* TODO Factorise with main *)
+          (* TODO Factorise with main *)
          Tag.init (Grammar2.tag_operations g);
          let query =
            time ~msg:"Parsing query" XPath.parse !Options.query
@@ -121,14 +120,14 @@ let _ =
          Gc.set (tuned_gc);
          let runtime =
            if !Options.count_only then
-           let module R = ResJIT.Make(NodeSet.Partial(NodeSet.Count)) in
-           let module M = Runtime.Make(R) in
-       (* mk_runtime run auto doc arg count print outfile  *)
-           mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
+             let module R = ResJIT.Make(NodeSet.Partial(NodeSet.Count)) in
+             let module M = Runtime.Make(R) in
+           (* mk_runtime run auto doc arg count print outfile  *)
+             mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
            else
              let module R = ResJIT.Mat in
              let module M = Runtime.Make(R) in
-           (* mk_runtime run auto doc arg count print outfile  *)
+             (* mk_runtime run auto doc arg count print outfile  *)
              mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None
          in
          runtime ();
@@ -149,9 +148,9 @@ let _ =
            (Tree.parse_xml_uri)
            !Options.input_file
        in
-       let () =
-         if !Options.save_file <> ""
-         then
+        let () =
+          if !Options.save_file <> ""
+          then
            time
              ~msg:"Writing file to disk"
              (Tree.save v)
index 03d24a9..cec31bc 100644 (file)
@@ -18,6 +18,7 @@ let verbose = ref false
 let text_index_type = ref 0
 let do_perf = ref false
 let twopass = ref false
+let repeat = ref 1
 
 let set_index_type = function
   | "default" -> text_index_type := 0
@@ -82,9 +83,14 @@ let spec = Arg.align
     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
 
     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
-                              set_index_type),
+                               set_index_type),
     " choose text index type";
 
+    "-r", Arg.Set_int(repeat),
+    " repeat query execution n time (benchmarking only, default 1)";
+
+
+
     "-v", Arg.Set(verbose), " verbose mode"; ] @
 IFNDEF NTRACE
 THEN [
index e57f0cb..8393ead 100644 (file)
@@ -15,3 +15,4 @@ val verbose : bool ref
 val text_index_type : int ref
 val do_perf : bool ref
 val twopass : bool ref
+val repeat : int ref