File tree 5 files changed +43
-2
lines changed
5 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 8
8
* .exe
9
9
* .native
10
10
* .byte
11
- _build
11
+ ocamlprof.dump
12
+ _build
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ https://opam.ocaml.org/doc/Packaging.html
4
4
https://github.com/ocaml/opam-repository
5
5
6
6
https://ocaml.org/learn/tutorials/performance_and_profiling.html
7
+ https://stackoverflow.com/questions/9061421/running-time-in-ocaml
8
+ http://caml.inria.fr/pub/docs/manual-ocaml/libref/Sys.html
9
+ http://caml.inria.fr/pub/docs/manual-ocaml/libref/Arg.html
7
10
8
11
http://numeraljs.com/
9
12
http://www.json-generator.com/
Original file line number Diff line number Diff line change 1
1
.PHONY : all clean token json lexer parser test
2
- .PHONY : build_parser debug_parser interfaces
2
+ .PHONY : build_parser debug_parser interfaces time_test
3
3
4
4
all : interfaces build_parser
5
5
make test | wc
6
+ make time_test
6
7
7
8
test :
8
9
./run_json_test.sh
9
10
11
+ time_test :
12
+ ./run_time_test.sh
13
+
10
14
debug_parser : build_parser
11
15
ocamldebug ./test_json_parser.byte
12
16
Original file line number Diff line number Diff line change
1
+ #! /bin/bash -x
2
+
3
+ ocamlopt -p -ccopt -O2 -o time_test_json \
4
+ json.ml lexer.ml parser.ml time_test_json.ml \
5
+ && ./time_test_json test_tiny.json \
6
+ && ./time_test_json test_small.json \
7
+ && echo Extracting test_medium.json.gz \
8
+ && time gunzip < test_medium.json.gz | ./time_test_json
Original file line number Diff line number Diff line change
1
+ let parse_in_chan in_chan () =
2
+ Parser. parse_top_level @@ Lexer. lex @@ Stream. of_channel @@ in_chan
3
+
4
+ let parse_file file () =
5
+ parse_in_chan @@ open_in file
6
+
7
+ let time f =
8
+ let t = Sys. time () in
9
+ let _ = f () in
10
+ Printf. printf " \n Execution time: %fs\n " (Sys. time() -. t)
11
+
12
+ let usage () =
13
+ Printf. printf " 1) Run: %s < input.json\n " Sys. argv.(0 ) ;
14
+ Printf. printf " 2) Run: %s input.json\n " Sys. argv.(0 )
15
+
16
+ let () =
17
+ match Array. length Sys. argv with
18
+ | 1 ->
19
+ Printf. printf " Parsing JSON from STDIN\n " ;
20
+ time @@ parse_in_chan stdin
21
+ | 2 ->
22
+ let file = Sys. argv.(1 ) in
23
+ Printf. printf " Parsing JSON from the file %s\n " file;
24
+ time @@ parse_file file
25
+ | _ -> usage ()
You can’t perform that action at this time.
0 commit comments