X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=unit_test.ml;h=1f7e73213ac0201a50fff965b2c3dc28c49387fe;hb=3445f7f08f15fe41e0d1bfaaabaacf60cdc10b61;hp=e52c533f633b8bb0661ccce8797233098df46fa5;hpb=5cc0fe57953445af433b00023e5f4b6c1d0fe549;p=SXSI%2Fxpathcomp.git diff --git a/unit_test.ml b/unit_test.ml index e52c533..1f7e732 100644 --- a/unit_test.ml +++ b/unit_test.ml @@ -5,19 +5,6 @@ (* Distributed under the terms of the LGPL (see LICENCE) *) (******************************************************************************) -let collect_tags v = - let rec aux acc v = - if Tree.Binary.is_node v - then - let tag = Tree.Binary.tag v - in - let acc = aux (Ptset.add tag acc) (Tree.Binary.first_child v) - in - aux (Ptset.add tag acc) (Tree.Binary.next_sibling v) - else acc - in - aux Ptset.empty v -;; if Array.length (Sys.argv) <> 2 @@ -29,18 +16,43 @@ then let doc = - try - Tree.Binary.parse_xml_uri Sys.argv.(1) - with - | _ -> - Printf.printf "Error parsing document\n"; - exit 2 -;; -let _ = Tag.init (Tree.Binary.tag_pool doc) -;; -let tags = (Ptset.add (Tag.tag "foo") (collect_tags doc)) + try + Tree.load Sys.argv.(1) + with + | _ -> + ( try + Tree.parse_xml_uri Sys.argv.(1) + with + | _ ->( + + Printf.printf "Error parsing document\n"; + exit 2)) ;; -let _ = Tree.Binary.test_xml_tree Format.std_formatter tags doc + +let full_traversal tree = + let rec loop t = + if Tree.is_node t + then + begin + (*ignore (Tree.tag t); *) + loop (Tree.node_child t); + loop (Tree.node_sibling t); + end + in loop tree ;; + + +let _ = Tag.init (Tree.tag_pool doc) +let time f x = + let t1 = Unix.gettimeofday () in + let r = f x in + let t2 = Unix.gettimeofday () in + let t = (1000. *.(t2 -. t1)) in + Printf.eprintf " %fms\n%!" t ; + r +;; +let _ = Printf.eprintf "Timing traversal ... ";; +let _ = time (full_traversal) doc +;;