+let test_loop tree tag =
+ let t' = Tree.tagged_descendant tree tag Tree.root in
+ let f = Hashtbl.create 4096
+ in
+ let jump t _ = Tree.tagged_following_below tree tag t Tree.root in
+ let g t ctx =
+ if t == Tree.nil then 0
+ else 1+ ((Hashtbl.find f (hash 101)) (jump t ctx) ctx)
+ in
+ Hashtbl.add f (hash 101) g;
+ (Hashtbl.find f (hash 101)) t' Tree.root
+
+let test_full tree =
+ let root = Tree.root in
+ let fin = Tree.closing tree root in
+ let rec loop t = if t <= fin then
+ let tag = Tree.tag tree t in
+(* let _ = Tag.to_string tag in *)
+ if tag == Tag.pcdata then (ignore (Tree.get_text tree t));
+ let t = (Obj.magic ((Obj.magic t) + 1)) in
+ loop t
+ in
+ loop root
+
+
+let test_loop2 tree tag =
+ let t' = Tree.tagged_descendant tree tag Tree.root in
+ let f = Hashtbl.create 4096
+ in
+ let jump t _ = Tree.tagged_following_below tree tag t Tree.root in
+ let rec g t ctx =
+ if t == Tree.nil then 0
+ else 1+ (match (Hashtbl.find f (hash 101)) with
+ `Foo ->g (jump t ctx) ctx
+ )
+ in
+ Hashtbl.add f (hash 101) `Foo;
+ g t' Tree.root
+
+let main v query_string output =
+
+ let _ = Tag.init (Tree.tag_pool v) in
+ Printf.eprintf "Parsing query : ";
+ let query = try
+ time
+ XPath.Parser.parse_string query_string
+ with
+ Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
+ in
+ let _ = Printf.eprintf "Number of nodes %i\n%!" (Tree.size v) in
+ let _ = Printf.eprintf "Timing first_child/next_sibling %!" in
+ let _ = time (Tree.benchmark_fsns) v in
+ let _ = Printf.eprintf "Timing jump to a %!" in
+ let _ = time (Tree.benchmark_jump v) (Tag.tag "a") in
+
+(* let _ = Printf.eprintf "Timing //keyword :" in
+ let r = time (test_loop v) (Tag.tag "keyword") in
+ let _ = Printf.eprintf "Count is %i\n%!" r in
+ let _ = Printf.eprintf "Timing //keyword 2:" in
+ let r = time (test_loop2 v) (Tag.tag "keyword") in
+ let _ = Printf.eprintf "Count is %i\n%!" r in
+ let _ = Printf.eprintf "Timing //node() :" in
+ let _ = time (test_full) v in *)
+ XPath.Ast.print Format.err_formatter query;
+ Format.fprintf Format.err_formatter "\n%!";