Browse Source

benchmark-reorg: split command into subcommands, add more json

It was inconvenient to run quick benchmarks before due to the fact that
there was no way to select a subset of benchmarks to run. This is fixed
by splitting the benchmarks into subcommands that only run benchmarks
for a specific parser.

The number of json input files has been expanded. These files were taken
from the attoparsec repository on GitHub. An ACKNOWLEDGEMENTS file was
added to note this.

Added a benchmark to see what the relative costs of float_of_string and
int_of_string are.
Spiros Eliopoulos 4 years ago
parent
commit
78b05cc74b

+ 2 - 0
benchmarks/data/ACKNOWLEDGEMENTS

@@ -0,0 +1,2 @@
+Several of the data files in this directory were taken from the attoparsec
+repository on GitHub. The source of twitter.json has been forgotten.

+ 1 - 0
benchmarks/data/twitter1.json

@@ -0,0 +1 @@
+{"results":[{"from_user_id_str":"80430860","profile_image_url":"http://a2.twimg.com/profile_images/536455139/icon32_normal.png","created_at":"Wed, 26 Jan 2011 07:07:02 +0000","from_user":"kazu_yamamoto","id_str":"30159761706061824","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Haskell Server Pages \u3063\u3066\u3001\u307e\u3060\u7d9a\u3044\u3066\u3044\u305f\u306e\u304b\uff01","id":30159761706061824,"from_user_id":80430860,"geo":null,"iso_language_code":"no","to_user_id_str":null,"source":"<a href="http://twitter.com/">web</a>"}],"max_id":30159761706061824,"since_id":0,"refresh_url":"?since_id=30159761706061824&q=haskell","next_page":"?page=2&max_id=30159761706061824&rpp=1&q=haskell","results_per_page":1,"page":1,"completed_in":0.012606,"since_id_str":"0","max_id_str":"30159761706061824","query":"haskell"}

File diff suppressed because it is too large
+ 0 - 0
benchmarks/data/twitter10.json


File diff suppressed because it is too large
+ 0 - 0
benchmarks/data/twitter20.json


+ 45 - 15
benchmarks/pure_benchmark.ml

@@ -13,17 +13,22 @@ let read file =
   with_file ~mode:[O_RDONLY] file ~f:(fun fd ->
     loop 0 size fd);
   Bigstring.of_string buf
+;;
 
 let zero =
   let len = 65_536 in
   Bigstring.of_string (String.make len '\x00')
+;;
 
-let make_endian name p =
+let make_bench name parser contents =
   Bench.Test.create ~name (fun () ->
-    match Angstrom.(parse_bigstring (skip_many p) zero) with
+    match Angstrom.(parse_bigstring parser contents) with
     | R.Ok _ -> ()
     | R.Error err -> failwith err)
 
+let make_endian name p        = make_bench name (Angstrom.skip_many p)   zero
+let make_json   name contents = make_bench name RFC7159.json             contents
+let make_http   name contents = make_bench name RFC2616.request          contents
 
 (* For input files involving trailing numbers, .e.g, [http-requests.txt.100],
  * go into the [benchmarks/data] directory and use the [replicate] script to
@@ -33,19 +38,44 @@ let make_endian name p =
  *
  *)
 let main () =
-  let big_twitter = read "benchmarks/data/twitter.json" in
+  let twitter1    = read "benchmarks/data/twitter1.json" in
+  let twitter10   = read "benchmarks/data/twitter10.json" in
+  let twitter20   = read "benchmarks/data/twitter20.json" in
+  let twitter_big = read "benchmarks/data/twitter.json" in
   let http_get    = read "benchmarks/data/http-requests.txt.100" in
-  Command.run (Bench.make_command [
-    Bench.Test.create ~name:"json" (fun () ->
-      match Angstrom.parse_bigstring RFC7159.json big_twitter with
-      | R.Ok _ -> ()
-      | R.Error err -> failwith err);
-    Bench.Test.create ~name:"http" (fun () ->
-      match Angstrom.(parse_bigstring (skip_many RFC2616.request) http_get) with
-      | R.Ok _ -> ()
-      | R.Error err -> failwith err);
-    make_endian "int64 le" Angstrom.LE.int64;
-    make_endian "int64 be" Angstrom.BE.int64;
-  ])
+  let json =
+    Bench.make_command [
+      make_json "twitter1"    twitter1;
+      make_json "twitter10"   twitter10;
+      make_json "twitter20"   twitter20;
+      make_json "twitter-big" twitter_big;
+    ]
+  in
+  let endian =
+    Bench.make_command [
+      make_endian "int64 le" Angstrom.LE.int64;
+      make_endian "int64 be" Angstrom.BE.int64;
+    ]
+  in
+  let http =
+    Bench.make_command [ make_http "http" http_get ] 
+  in
+  let numbers =
+    Bench.make_command [ 
+      Bench.Test.create ~name:"float" (fun () ->
+        float_of_string "1.7242915150166418e+36");
+      Bench.Test.create ~name:"int" (fun () ->
+        int_of_string "172429151501664");
+      Bench.Test.create ~name:"int-float" (fun () ->
+        float_of_string "172429151501664");
+    ]
+  in
+  Command.run
+    (Command.group ~summary:"various angstrom benchmarks" 
+      [ "json"   , json
+      ; "endian" , endian
+      ; "http"   , http 
+      ; "numbers", numbers
+    ])
 
 let () = main ()

Some files were not shown because too many files changed in this diff