Data_encoding: Refresh benchmarks
This commit is contained in:
parent
2b82a588e1
commit
d1c2f631d5
@ -11,7 +11,7 @@ let bench ?(num_iterations=1000) name thunk =
|
|||||||
Gc.full_major () ;
|
Gc.full_major () ;
|
||||||
Gc.compact () ;
|
Gc.compact () ;
|
||||||
let start_time = Sys.time () in
|
let start_time = Sys.time () in
|
||||||
for i = 0 to (num_iterations - 1) do
|
for _i = 0 to (num_iterations - 1) do
|
||||||
thunk ()
|
thunk ()
|
||||||
done ;
|
done ;
|
||||||
let end_time = Sys.time () in
|
let end_time = Sys.time () in
|
||||||
@ -21,17 +21,31 @@ let bench ?(num_iterations=1000) name thunk =
|
|||||||
(end_time -. start_time)
|
(end_time -. start_time)
|
||||||
num_iterations
|
num_iterations
|
||||||
|
|
||||||
let bench_json_binary ?(num_iterations=1000) name encoding value =
|
let read_stream encoding bytes =
|
||||||
|
let rec loop bytes status =
|
||||||
|
match bytes, status with
|
||||||
|
| [], Data_encoding.Binary.Success _ -> ()
|
||||||
|
| bytes :: bytess, Await f -> loop bytess (f bytes)
|
||||||
|
| _, _ -> assert false in
|
||||||
|
loop bytes (Data_encoding.Binary.read_stream encoding)
|
||||||
|
|
||||||
|
let bench_all ?(num_iterations=1000) name encoding value =
|
||||||
bench ~num_iterations ("writing " ^ name ^ " json")
|
bench ~num_iterations ("writing " ^ name ^ " json")
|
||||||
(fun () -> ignore @@ Data_encoding_ezjsonm.to_string @@ Data_encoding.Json.construct encoding value) ;
|
(fun () -> ignore @@ Data_encoding.Json.to_string @@ Data_encoding.Json.construct encoding value) ;
|
||||||
let encoded_json = Data_encoding_ezjsonm.to_string @@ Data_encoding.Json.construct encoding value in
|
|
||||||
bench ~num_iterations ("reading " ^ name ^ " json")
|
|
||||||
(fun () -> Data_encoding.Json.destruct encoding (Ezjsonm.from_string encoded_json)) ;
|
|
||||||
bench ~num_iterations ("writing " ^ name ^ " binary")
|
bench ~num_iterations ("writing " ^ name ^ " binary")
|
||||||
(fun () -> ignore @@ Data_encoding.Binary.to_bytes encoding value) ;
|
(fun () -> ignore @@ Data_encoding.Binary.to_bytes_exn encoding value) ;
|
||||||
let encoded_binary = Data_encoding.Binary.to_bytes encoding value in
|
let encoded_json = Data_encoding.Json.to_string @@ Data_encoding.Json.construct encoding value in
|
||||||
|
bench ~num_iterations ("reading " ^ name ^ " json")
|
||||||
|
(fun () -> ignore (Data_encoding.Json.destruct encoding (Ezjsonm.from_string encoded_json))) ;
|
||||||
|
let encoded_binary = Data_encoding.Binary.to_bytes_exn encoding value in
|
||||||
bench ~num_iterations ("reading " ^ name ^ " binary")
|
bench ~num_iterations ("reading " ^ name ^ " binary")
|
||||||
(fun () -> ignore @@ Data_encoding.Binary.of_bytes_exn encoding encoded_binary)
|
(fun () -> ignore @@ Data_encoding.Binary.of_bytes encoding encoded_binary ) ;
|
||||||
|
bench ~num_iterations ("reading " ^ name ^ " streamed binary (one chunk)")
|
||||||
|
(fun () -> read_stream encoding [encoded_binary]) ;
|
||||||
|
bench ~num_iterations
|
||||||
|
("reading " ^ name ^ " streamed binary (small chunks)")
|
||||||
|
(fun () -> read_stream encoding (MBytes.cut 1 encoded_binary)) ;
|
||||||
|
()
|
||||||
|
|
||||||
type t =
|
type t =
|
||||||
| A of string
|
| A of string
|
||||||
@ -73,18 +87,28 @@ let cases_encoding : t Data_encoding.t =
|
|||||||
])
|
])
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
(* bench_json_binary "1000_element_int_list" Data_encoding.(list int31) (Array.to_list (Array.make 1000 0)) *)
|
|
||||||
(* bench_json_binary "option_element_int_list" Data_encoding.(list (option int31)) (Array.to_list (Array.make 1000 (Some 0))) *)
|
bench_all
|
||||||
(* bench_json_binary "option_option_element_list"
|
"10000_element_int_list"
|
||||||
* Data_encoding.(list (option (option int31)))
|
Data_encoding.(list int31)
|
||||||
* (Array.to_list (Array.make 1000 (Some None))) *)
|
~num_iterations:1000
|
||||||
bench_json_binary "option_option_result_element_list"
|
(Array.to_list (Array.make 10000 0)) ;
|
||||||
Data_encoding.(list (result (option (option int31)) string))
|
|
||||||
(Array.to_list (Array.make 1000 (Error "hello")))
|
bench_all
|
||||||
(* bench ~num_iterations:10000 "binary_encoding"
|
"option_element_int_list"
|
||||||
* (let encoding = Data_encoding.(list cases_encoding) in
|
Data_encoding.(list (option int31))
|
||||||
* let value = Array.to_list (Array.make 1000 (R (R (A "asdf", B true), F 1.0))) in
|
(Array.to_list (Array.make 10000 (Some 0))) ;
|
||||||
* (fun () -> ignore @@ Data_encoding.Binary.to_bytes encoding value)) *)
|
|
||||||
(* bench_json_binary "binary_encoding_large_list"
|
let encoding = Data_encoding.(list (result (option int31) string)) in
|
||||||
* Data_encoding.(list cases_encoding)
|
let value = (Array.to_list (Array.make 10000 (Error "hello"))) in
|
||||||
* (Array.to_list (Array.make 10000 (R (R (A "asdf", B true), F 1.0)))) *)
|
bench_all "option_result_element_list" encoding value;
|
||||||
|
|
||||||
|
let encoding = Data_encoding.(list cases_encoding) in
|
||||||
|
let value = Array.to_list (Array.make 1000 (R (R (A "asdf", B true), F 1.0))) in
|
||||||
|
bench ~num_iterations:1000 "binary_encoding"
|
||||||
|
(fun () -> ignore @@ Data_encoding.Binary.to_bytes encoding value) ;
|
||||||
|
|
||||||
|
bench_all "binary_encoding_large_list"
|
||||||
|
Data_encoding.(list cases_encoding)
|
||||||
|
(Array.to_list (Array.make 2000 (R (R (A "asdf", B true), F 1.0))))
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
(executables
|
(executables
|
||||||
((names (test
|
((names (test
|
||||||
;; bench_data_encoding
|
bench_data_encoding
|
||||||
))
|
))
|
||||||
(libraries (tezos-stdlib
|
(libraries (tezos-stdlib
|
||||||
tezos_data_encoding
|
tezos_data_encoding
|
||||||
@ -14,13 +14,17 @@
|
|||||||
(alias
|
(alias
|
||||||
((name buildtest)
|
((name buildtest)
|
||||||
(deps (test.exe
|
(deps (test.exe
|
||||||
;; bench_data_encoding.exe
|
bench_data_encoding.exe
|
||||||
))))
|
))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
((name runtest)
|
((name runtest)
|
||||||
(action (run ${exe:test.exe}))))
|
(action (run ${exe:test.exe}))))
|
||||||
|
|
||||||
|
(alias
|
||||||
|
((name run_bench)
|
||||||
|
(action (run ${exe:bench_data_encoding.exe}))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
((name runtest_indent)
|
((name runtest_indent)
|
||||||
(deps ((glob_files *.ml*)))
|
(deps ((glob_files *.ml*)))
|
||||||
|
Loading…
Reference in New Issue
Block a user