-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from mransan/wip-encode-backward-with-c-stubs
encode backward and use C stubs
- Loading branch information
Showing
18 changed files
with
622 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ on: | |
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
jobs: | ||
run: | ||
name: Build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ ocaml_protoc.native | |
*.orig | ||
_opam | ||
*.data | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec dune exec --profile=release -- benchs/bin/run.exe $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
(executable | ||
(name run) | ||
(ocamlopt_flags :standard -inline 100) | ||
(libraries pbrt)) | ||
|
||
(rule | ||
(targets foo.ml foo.mli) | ||
(deps foo.proto) | ||
(action | ||
(run ocaml-protoc %{deps} --binary --pp --ml_out .))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
syntax = "proto3"; | ||
|
||
message Person { | ||
string name = 1; | ||
sint64 age = 2; | ||
} | ||
|
||
message Store { | ||
string address = 1; | ||
repeated Person employees = 2; | ||
repeated Person clients = 3; | ||
} | ||
|
||
message Company { | ||
string name = 1; | ||
repeated Store stores = 2; | ||
repeated Company subsidiaries = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
open Foo | ||
|
||
let spf = Printf.sprintf | ||
|
||
(* company, with [n] stores and [2^depth] subsidiaries *) | ||
let rec mk_company ~n ~depth : company = | ||
{ | ||
name = "bigcorp"; | ||
subsidiaries = | ||
(if depth = 0 then | ||
[] | ||
else ( | ||
let c = mk_company ~n ~depth:(depth - 1) in | ||
[ c; c ] | ||
)); | ||
stores = | ||
List.init n (fun i -> | ||
{ | ||
address = spf "%d foobar street" i; | ||
clients = | ||
List.init 2 (fun j -> | ||
{ | ||
name = spf "client_%d_%d" i j; | ||
age = Int64.of_int ((j mod 30) + 15); | ||
}); | ||
employees = | ||
List.init 2 (fun j -> | ||
{ | ||
name = spf "employee_%d_%d" i j; | ||
age = Int64.of_int ((j mod 30) + 18); | ||
}); | ||
}); | ||
} | ||
|
||
let comp = mk_company ~n:3 ~depth:2 | ||
|
||
let () = | ||
let n = ref 3 in | ||
let depth = ref 2 in | ||
let iters = ref 100 in | ||
|
||
let opts = | ||
[ | ||
"-n", Arg.Set_int n, " size for data"; | ||
"--depth", Arg.Set_int depth, " nesting depth for data"; | ||
"--iters", Arg.Set_int iters, " number of iterations"; | ||
] | ||
|> Arg.align | ||
in | ||
Arg.parse opts ignore ""; | ||
|
||
Printf.printf "n=%d, depth=%d, iters=%n\n%!" !n !depth !iters; | ||
let comp = mk_company ~n:!n ~depth:!depth in | ||
|
||
let enc = Pbrt.Encoder.create ~size:(64 * 1024) () in | ||
|
||
Sys.opaque_identity (Foo.encode_pb_company comp enc); | ||
let size = String.length @@ Pbrt.Encoder.to_string enc in | ||
Printf.printf "size=%d B\n%!" size; | ||
|
||
for _i = 1 to !iters do | ||
Pbrt.Encoder.clear enc; | ||
Sys.opaque_identity (Foo.encode_pb_company comp enc) | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.