]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/mqint.ml
Time misurations patched.
[helm.git] / helm / ocaml / mathql_interpreter / mqint.ml
index 7731d9e2e2ac26af77bba6ba880152fdf1cbe4b8..89f635aff227e8eba0c7347e0d1730c3c8f0ad13 100644 (file)
@@ -51,38 +51,67 @@ let check () = Dbconn.pgc ()
 
 exception BooleExpTrue
 
+let stat = ref true
+
+let set_stat b = stat := b
+
 (* valuta una MathQL.set_exp e ritorna un MathQL.resource_set *)
 
 let rec exec_set_exp c = function
    |MathQL.SVar svar -> List.assoc svar c.svars
    |MathQL.RVar rvar -> [List.assoc rvar c.rvars]  
    | MathQL.Ref vexp -> List.map (fun s -> (s,[])) (exec_val_exp c vexp)
-   | MathQL.Intersect (sexp1, sexp2) -> intersect_ex (exec_set_exp c sexp1) (exec_set_exp c sexp2)    
+   | MathQL.Intersect (sexp1, sexp2) ->    
+        let before = Sys.time() in
+       let rs1 = exec_set_exp c sexp1 in
+       let rs2 = exec_set_exp c sexp2 in
+        let res = intersect_ex rs1 rs2 in
+        let after = Sys.time() in
+        let ll1 = string_of_int (List.length rs1) in
+        let ll2 = string_of_int (List.length rs2) in
+        let diff = string_of_float (after -. before) in
+       if !stat then
+        (print_endline("INTERSECT(" ^ ll1 ^ "," ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^
+         ": " ^ diff ^ "s");
+         flush stdout);
+        res
    | MathQL.Union (sexp1, sexp2) -> 
         let before = Sys.time () in
        let res = union_ex (exec_set_exp c sexp1) (exec_set_exp c sexp2) in
-       let after = Sys.time () in
+       let after = Sys.time() in
        let diff = string_of_float (after -. before) in
-        print_endline ("UNION: " ^ diff ^ "s") ;
-        flush stdout ;
+        if !stat then
+       (print_endline ("UNION: " ^ diff ^ "s");
+         flush stdout);
         res                    
    | MathQL.LetSVar (svar, sexp1, sexp2) ->
-        let before = Sys.time () in
+        let before = Sys.time() in
         let c1 = upd_svars c ((svar, exec_set_exp c sexp1) :: c.svars) in 
        let res = exec_set_exp c1 sexp2 in
-       print_string ("LETIN " ^ svar ^ " = " ^ string_of_int (List.length res) ^ ": ") ;
-       print_endline (string_of_float (Sys.time () -. before) ^ "s") ;
-        flush stdout ; res                     
+       if !stat then
+       (print_string ("LETIN " ^ svar ^ " = " ^ string_of_int (List.length res) ^ ": ");
+        print_endline (string_of_float (Sys.time() -. before) ^ "s");
+         flush stdout); 
+       res                     
    | MathQL.LetVVar (vvar, vexp, sexp) ->
-        let before = Sys.time () in
+        let before = Sys.time() in
        let c1 = upd_vvars c ((vvar, exec_val_exp c vexp) :: c.vvars) in
        let res = exec_set_exp c1 sexp in
-       print_string ("LETIN " ^ vvar ^ " = " ^ string_of_int (List.length res) ^ ": ") ;
-        print_endline (string_of_float (Sys.time () -. before) ^ "s") ;
-        flush stdout ; res
-   | MathQL.Relation (rop, path, sexp, attl) -> relation_ex rop path (exec_set_exp c sexp) attl
+       if !stat then
+       (print_string ("LETIN " ^ vvar ^ " = " ^ string_of_int (List.length res) ^ ": ");
+         print_endline (string_of_float (Sys.time() -. before) ^ "s");
+         flush stdout); 
+       res
+   | MathQL.Relation (rop, path, sexp, attl) -> 
+        let before = Sys.time() in
+        let res = relation_ex rop path (exec_set_exp c sexp) attl in
+       if !stat then 
+       (print_string ("RELATION " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
+         print_endline (string_of_float (Sys.time() -. before) ^ "s");
+         flush stdout);
+        res   
    | MathQL.Select (rvar, sexp, bexp) ->
-        let before = Sys.time () in
+        let before = Sys.time() in
         let rset = (exec_set_exp c sexp) in
         let rec select_ex rset =
         match rset with 
@@ -92,9 +121,11 @@ let rec exec_set_exp c = function
                   else select_ex tl
         in 
        let res = select_ex rset in
-       print_string ("SELECT " ^ rvar ^ " = " ^ string_of_int (List.length res) ^ ": ") ;
-       print_endline (string_of_float (Sys.time () -. before) ^ "s") ;
-        flush stdout ; res
+       if !stat then
+       (print_string ("SELECT " ^ rvar ^ " = " ^ string_of_int (List.length res) ^ ": ");
+        print_endline (string_of_float (Sys.time() -. before) ^ "s");
+         flush stdout); 
+       res
    | MathQL.Diff (sexp1, sexp2) -> diff_ex (exec_set_exp c sexp1) (exec_set_exp c sexp2)
    | _ -> assert false
    
@@ -126,7 +157,7 @@ and exec_boole_exp c = function
                                     in       
                                      sub_prod attl 
         in
-        prod c latt;false
+        prod c latt; false
         with BooleExpTrue -> true
 
 (* valuta una MathQL.val_exp e ritorna un MathQL.value *)