+let default_gc = Gc.get()
+let tuned_gc = { Gc.get() with
+ Gc.minor_heap_size = 4*1024*1024;
+ Gc.major_heap_increment = 1024*1024;
+ Gc.max_overhead = 1000000;
+ }
+let hash x = 131*x/(x-1+1)
+
+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 test_text doc =
+ let _ = Printf.eprintf "Contains(bree)" in
+ let _ = time (Tree.test_contains doc) "bree" in
+ let _ = Printf.eprintf "Contains(brain)" in
+ let _ = time (Tree.test_contains doc) "brain" in
+ let _ = Printf.eprintf "Contains(brain)" in
+ let i = time (Tree.test_contains doc) "brain" in
+ let _ = Printf.eprintf "%i\nContains(Australia)" i in
+ let i = time (Tree.test_contains doc) "AUSTRALIA" in
+ let _ = Printf.eprintf "%i\n Contains(1930)" i in
+ let i = time (Tree.test_contains doc) "1930" in
+ let _ = Printf.eprintf "%i\n startswith(bar)" i in
+ let i = time (Tree.test_prefix doc) "bar" in
+ let _ = Printf.eprintf "%i\n endswith(LAND)" i in
+ let i = time (Tree.test_suffix doc) "LAND" in
+ let _ = Printf.eprintf "%i\n =(2001)" i in
+ let i = time (Tree.test_equals doc) "2001" in
+ let _ = Printf.eprintf "%i\n =(Nguyen)" i in
+ let i = time (Tree.test_equals doc) "Nguyen" in
+ Printf.eprintf "%i\n" i ;
+ ()