1 (******************************************************************************)
2 (* SXSI : XPath evaluator *)
3 (* Kim Nguyen (Kim.Nguyen@nicta.com.au) *)
4 (* Copyright NICTA 2008 *)
5 (* Distributed under the terms of the LGPL (see LICENCE) *)
6 (******************************************************************************)
13 let t1 = Unix.gettimeofday () in
15 let t2 = Unix.gettimeofday () in
16 let t = (1000. *.(t2 -. t1)) in
18 Printf.eprintf " %fms\n%!" t ;
21 let total_time () = List.fold_left (+.) 0. !l;;
24 let main v query output =
25 let _ = Tag.init (Tree.tag_pool v) in
26 Printf.eprintf "Parsing query : ";
29 XPath.Parser.parse_string query
31 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
33 XPath.Ast.print Format.err_formatter query;
34 Format.fprintf Format.err_formatter "\n%!";
35 (* Printf.eprintf "Dummy iteration : ";
36 time (fill_hashtag) v;
37 Printf.eprintf "Dummy iteration (tag access cached) : ";
38 time (fill_hashtag) v;
40 Printf.eprintf "Compiling query : ";
41 let auto,ltags,contains = time XPath.Compile.compile query in
42 let _ = Ata.dump Format.err_formatter auto in
43 let _ = Printf.eprintf "%!" in
44 let _ = match contains with
47 let r = Tree.count v s
49 Printf.eprintf "Global count is %i, using " r;
50 if r < 60000 then begin
51 Printf.eprintf "TextCollection contains\nCalling global contains : ";
52 time (Tree.init_contains v) s
55 Printf.eprintf "Naive contains\nCalling global contains : ";
56 time (Tree.init_naive_contains v) s
59 Printf.eprintf "Execution time %s : " (if !Options.count_only then "(counting only)" else "");
61 if !Options.count_only then
62 let r = time ( run_count auto )v in
63 let _ = Printf.eprintf "Number of nodes in the result set : %i\n%!" r
66 (* let _ = Gc.set ({ Gc.get() with Gc.max_overhead = 1000000; Gc.space_overhead = 100 }) in *)
67 let result,rcount = time (if !Options.time then run_time auto else run auto) v in
68 Printf.eprintf "Number of nodes in the result set : %i\n" rcount;
69 Printf.eprintf "\n%!";
74 Printf.eprintf "Serializing results : ";
76 let oc = open_out f in
77 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
79 Tree.print_xml_fast oc t;
80 output_char oc '\n') result) ();
83 let _ = Ata.dump Format.err_formatter auto in
84 Printf.eprintf "Total running time : %fms\n%!" (total_time())
87 Options.parse_cmdline();;
90 if (Filename.check_suffix !Options.input_file ".srx")
93 Printf.eprintf "Loading from file : ";
94 time (Tree.load ~sample:!Options.sample_factor )
95 (Filename.chop_suffix !Options.input_file ".srx");
99 time (fun () -> let v = Tree.parse_xml_uri !Options.input_file;
100 in Printf.eprintf "Parsing document : %!";v
103 if !Options.save_file <> ""
105 Printf.eprintf "Writing file to disk : ";
106 time (Tree.save v) !Options.save_file;
110 main v !Options.query !Options.output_file;;
114 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
116 Tree.DEBUGTREE.print_stats Format.err_formatter;;