Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
8d266e7
Apply ocamlformat.0.15.0 on s.ml
dinosaure Aug 19, 2020
2166e1b
Delete useless interfaces.
dinosaure Aug 19, 2020
e718db3
Add some useful functions into the description of the module HASH
dinosaure Aug 19, 2020
1e7b42f
Apply ocamlformat.0.15.0 on blob.ml{,i}
dinosaure Aug 19, 2020
e87e9a9
Delete the old interfaces of the Blob object.
dinosaure Aug 19, 2020
c0afb3f
Reduce the intf. of Blob and parameter it with the new type hash
dinosaure Aug 19, 2020
46c0610
Define an abstract type Blob.t (de-functorize)
dinosaure Aug 19, 2020
61fca08
Constraint Blob.Make over the type hash instead the module Hash
dinosaure Aug 19, 2020
55ad08c
Documentation on Blob module
dinosaure Aug 19, 2020
e107474
Delete useless /meta/ constructor of the Blob format
dinosaure Aug 19, 2020
eea6ddc
Encore.Lole.pp_bigstring does not exist anymore, use Fmt.string instead
dinosaure Aug 19, 2020
8a9c0ab
Apply ocamlformat.0.15.0 on tree.ml{,i}
dinosaure Aug 19, 2020
8ac36dc
Delete the old interfaces of the Tree object.
dinosaure Aug 19, 2020
c4b0a22
Reduce the intf. of Tree and parameter it with the new type hash
dinosaure Aug 19, 2020
42af4ce
Define an abstract type Tree.t (private) (de-functorize)
dinosaure Aug 19, 2020
5100f73
Constraint Tree.Make over the type hash instead the module Hash
dinosaure Aug 19, 2020
94a3581
Documentation on Tree module
dinosaure Aug 19, 2020
5ced50c
Delete useless /meta/ constructor of the Tree format
dinosaure Aug 20, 2020
b4ffe1d
Add Stream module
dinosaure Aug 20, 2020
c06297b
Use the Stream module to /digest/ a Git Tree object
dinosaure Aug 20, 2020
6e8b659
Add a (non-exposed) Log module into the Tree module (to help to debug)
dinosaure Aug 20, 2020
f3df554
Apply ocamlformat.0.15.0 on commit.ml{,i}
dinosaure Aug 20, 2020
f4b416b
Delete the old interface of the Commit object.
dinosaure Aug 20, 2020
30626b5
Reduce the intf. of Commit and parameter it with the new type hash
dinosaure Aug 20, 2020
2292ef6
Define an abstract type Commit.t (de-functorize)
dinosaure Aug 20, 2020
7ded942
Constraint Commit.Make over the type hash instead the module Hash
dinosaure Aug 20, 2020
e42f539
Documentation on Commit module
dinosaure Aug 20, 2020
508f63d
Apply ocamlformat.0.15.0 on tag.ml{,i}
dinosaure Aug 20, 2020
31fd9fe
Delete useless /meta/ constructor of the Commit format
dinosaure Aug 20, 2020
6f0fdfc
Use the Stream module to /digest/ a Git Commit object
dinosaure Aug 20, 2020
2b293e5
Apply ocamlformat.0.15.0 on user.ml{,i}
dinosaure Aug 20, 2020
ec40133
Delete useless /meta/ constructor of the User format
dinosaure Aug 20, 2020
ae4c1e1
Apply ocamlformat.0.15.0 on hash.ml
dinosaure Aug 20, 2020
cccf1f0
Minor update on the module Hash to fit into new interface
dinosaure Aug 20, 2020
dc5189b
Delete useless Crc32 module (use [checkseum] instead)
dinosaure Aug 20, 2020
9e3cd2d
Delete Inflate and Deflate module.
dinosaure Aug 20, 2020
7b904df
Delete Helper module.
dinosaure Aug 20, 2020
dcdf135
Delete the old interface of the Tag object.
dinosaure Aug 20, 2020
d945d2b
Reduce the intf. of Tag and parameter it with the new type hash
dinosaure Aug 20, 2020
bbdda49
Define an abstract type Tag.t (de-functorize)
dinosaure Aug 20, 2020
e3c2bc5
Constraint Tag.Make over the type hash instead the module Hash
dinosaure Aug 20, 2020
d21650a
Documentation on Tag module
dinosaure Aug 20, 2020
bad8de6
Apply ocamlformat.0.15.0 on reference.ml{,i}
dinosaure Aug 24, 2020
6492b3f
Remove useless Git.Reference.P (Partial) sub-module
dinosaure Aug 24, 2020
e59a3af
Delete the old interface of Git reference
dinosaure Aug 24, 2020
72170b7
Delete the Path module
dinosaure Aug 24, 2020
a2c9d39
Delete the old interface of the Reference object.
dinosaure Aug 24, 2020
993cabf
Delete the old IO interface of the Reference object.
dinosaure Aug 24, 2020
4a6b681
De-functorize the Reference module.
dinosaure Aug 24, 2020
3f26c28
Reduce the intf. of Reference and parameter [head_contents]/[contents…
dinosaure Aug 24, 2020
7032353
Provide new I/O operations on References from a simple [store] impl.
dinosaure Aug 24, 2020
24e0f99
Provide a common way to extract references from a /packed-refs/ file
dinosaure Aug 24, 2020
fcba5ef
Update copyright about impl. of Git.Reference module
dinosaure Aug 24, 2020
da58597
Remove infix operators of LWT into Reference module
dinosaure Aug 24, 2020
4003fec
Delete log on Reference module
dinosaure Aug 24, 2020
fc3a610
Update the implementation of Git reference.
dinosaure Aug 24, 2020
770d17b
Implement Reference.{Map,Set}
dinosaure Aug 24, 2020
05e997c
De-functorize Git.Reference.contents/[head_contents]
dinosaure Aug 24, 2020
47a3b78
Provide a useless module signature Git.Reference.S
dinosaure Aug 24, 2020
871cd50
Apply ocamlformat.0.15.0 on minimal.ml
dinosaure Aug 24, 2020
9c54377
Delete the compression accessor from the Minimal intf. of Git
dinosaure Aug 24, 2020
de86e76
Use the definition of the type [hash] instead the module [Hash]
dinosaure Aug 24, 2020
abc9b6d
Delete useless Inflate/Deflate module from the minimal intf. of Git
dinosaure Aug 24, 2020
a844224
Redefine Value into the minimal intf. of Git via hash type
dinosaure Aug 24, 2020
1525a6d
Redefine Reference into the minimal intf. of Git via hash type
dinosaure Aug 24, 2020
163486d
Delete the useless common type buffer from the minimal intf. of Git
dinosaure Aug 24, 2020
ddf4ce2
Git.contents does not fail anymore.
dinosaure Aug 24, 2020
359ed48
Use the type hash instead the module Hash into the minimal intf. of Git
dinosaure Aug 24, 2020
19fb87d
Delete the Pack sub-module from the minimal intf. of Git
dinosaure Aug 24, 2020
9964504
Add [batch_write] into the minimal intf. of Git
dinosaure Aug 24, 2020
a056a89
Extend possible error from the minimal/common intf. of Git
dinosaure Aug 24, 2020
f07a0ec
Documentation on Minimal module
dinosaure Aug 24, 2020
2331adc
Documentation on S module
dinosaure Aug 24, 2020
f2006c6
Delete useless /meta/ constructor of the Tag format
dinosaure Aug 24, 2020
f1194d8
Use the Stream module to /digest/ a Git Tag object
dinosaure Aug 24, 2020
f55af72
Apply ocamlformat.0.15.0 on value.ml{,i}
dinosaure Aug 24, 2020
b005721
Delete the old interface of the Git object.
dinosaure Aug 25, 2020
b9a3b50
Reduce the intf. of Value and parameter it with the new type hash
dinosaure Aug 25, 2020
7206edb
Define a type Value.t (de-functorize)
dinosaure Aug 25, 2020
9f269cc
Delete verbose sub-module to encode a Git value.
dinosaure Aug 25, 2020
dcfb817
Expose easy way to encode/decode Git object.
dinosaure Aug 25, 2020
f44e2f1
Constraint Value.Make over the type hash instead the module Hash
dinosaure Aug 25, 2020
45a7a98
Delete useless /meta/ constructor of the Value format
dinosaure Aug 25, 2020
3e0dd18
Apply ocamlformat.0.15.0 on mem.ml{,i}
dinosaure Aug 25, 2020
bc1ca0d
Delete an old documentation about [Git.Mem]
dinosaure Aug 25, 2020
ea63882
De-functorize [Git.Mem] module and constraint it over the type [hash]
dinosaure Aug 25, 2020
7c00fd0
Redefine [Git.Mem.v] to create a Git store.
dinosaure Aug 25, 2020
bd96ad7
Add a [Sync] module to be able to [fetch]/[push].
dinosaure Aug 25, 2020
4134fe1
Documentation on Mem module
dinosaure Aug 25, 2020
a9bb7ee
Rename [Cstruct_buffer] to [Cstruct_append] and update the logic of it.
dinosaure Aug 25, 2020
5548c30
Apply ocamlformat.0.15.0 on sync.ml{,i}
dinosaure Aug 25, 2020
fae7b7a
Delete the old interface of [Sync]
dinosaure Aug 25, 2020
2257ccb
Propose a better interface about the [Sync] module.
dinosaure Aug 25, 2020
29dcd79
Integrate Not-So-Smart
dinosaure Aug 25, 2020
ad6d872
Capability module was added into the nss library
dinosaure Aug 25, 2020
401eb7f
Negociator module was /conceptually/ moved into the new nss library
dinosaure Aug 25, 2020
697f85b
Gri module was /conceptually/ move into the nss library
dinosaure Aug 25, 2020
2ee2393
TCP module was deleted/moved into the new nss library
dinosaure Aug 25, 2020
1f66954
Add an implementation of /loose/ files
dinosaure Aug 25, 2020
b32237e
Delete the old implementation of Git /loose/ objects
dinosaure Aug 25, 2020
2255519
Smart module was /conceptually/ moved into the new nss library
dinosaure Aug 25, 2020
031af01
Apply ocmalformat.0.15.0 on object_graph.ml{,i}
dinosaure Aug 25, 2020
471777f
Delete the old intf. of Object_graph module.
dinosaure Aug 25, 2020
4f1c770
Reduce the intf. of Object_graph and parameter it with new type hash …
dinosaure Aug 25, 2020
5569eaf
Constraint Object_graph.Make over the type hash and the type store
dinosaure Aug 25, 2020
5b88d05
Apply ocamlformat.0.15.0 on search.ml{,i}
dinosaure Aug 25, 2020
43d5eb0
Constraint Search.Make over the type hash and the type store
dinosaure Aug 25, 2020
d10757d
Reduce required STORE interface to make a breadth first search module
dinosaure Aug 25, 2020
04f2a1d
Rename functor argument of Traverse_bfs.Make from [S] to [Store]
dinosaure Aug 25, 2020
3833302
Apply ocamlformat.0.15.0 on traverse_bfs.ml
dinosaure Aug 26, 2020
b4f18a0
Integrate Carton
dinosaure Aug 26, 2020
378b207
Add [carton-lwt] which is a specialisation of Carton with LWT
dinosaure Aug 26, 2020
6291e39
Add [carton-git] to provide an impl. which needs an append-only store
dinosaure Aug 26, 2020
de69f9d
Unpack module is replaced by Carton
dinosaure Aug 26, 2020
67920ae
Delete the second-pass module which is replaced by Carton
dinosaure Aug 26, 2020
bd56151
Delete the index-pack module replaced by Carton.
dinosaure Aug 26, 2020
906f3c2
Delete the Pack and Collector module replaced by Carton.
dinosaure Aug 26, 2020
d13945a
Delete the way to handle PACK file (from disk or network).
dinosaure Aug 26, 2020
e186039
Delete useless modules used by the old impl. of the PACK file
dinosaure Aug 26, 2020
d3e6d01
Delete Revision module which is not really useful
dinosaure Aug 26, 2020
6e3a5ac
Delete the useless error module
dinosaure Aug 26, 2020
5d982cf
Update the implementation of the in-memory Git store
dinosaure Aug 26, 2020
40a7277
Re-apply the [Git.Mem.Store] functor with right arguments
dinosaure Aug 26, 2020
f91f2c0
Add the [Git.Mem.Sync] module to provide [fetch]/[push] in-memory
dinosaure Aug 26, 2020
a1424a5
Apply ocamlformat.0.15.0 on store.ml{,i}
dinosaure Aug 26, 2020
cbb0875
Delete LOOSE and PACK useless from [Git.Store]
dinosaure Aug 26, 2020
f1d5ba5
Delete the old interface [Git.Store.S]
dinosaure Aug 26, 2020
87dd485
Add a reference space to store references of a Git store.
dinosaure Aug 26, 2020
8c5f057
Add a /major/ space and a way to get IDX files from PACK files.
dinosaure Aug 26, 2020
9531d05
Re-update [Git.Store.Make] to require minor/major/reference heap and …
dinosaure Aug 26, 2020
2a14e27
Re-implement [Git.Store.Make] over minor/major/reference heaps
dinosaure Aug 26, 2020
4f19b8f
Delete bad binaries about git
dinosaure Aug 26, 2020
9a0bcc1
Update exported modules by the first-entry point [Git]
dinosaure Aug 26, 2020
2f3075f
The HTTP implementation of Git is now a part of [nss]
dinosaure Aug 26, 2020
efacbe3
[git-mirage] is not needed anymore where it is a specialisation of [S…
dinosaure Aug 26, 2020
e426b13
Update dune file to compile Git core library
dinosaure Aug 26, 2020
1d617ef
Update git-top
dinosaure Aug 26, 2020
d3a52e8
Idea of file-system does not exist anymore to implement [git-unix]
dinosaure Aug 26, 2020
a033a42
Idea of [Net] required by [Sync] is replace by the new version of Con…
dinosaure Aug 26, 2020
cd1dc68
New implementation of [git-unix].
dinosaure Aug 26, 2020
43156b7
Delete the old (buggy) implementation of the [.git/index] file
dinosaure Aug 26, 2020
1a7be9b
Add the new implementation of the [.git/index] file.
dinosaure Aug 26, 2020
318e045
[git-unix] should not provide the HTTP implementation.
dinosaure Aug 26, 2020
e93d573
Update tests
dinosaure Aug 26, 2020
8163047
A small bench about the extraction of an object from a PACK file
dinosaure Aug 26, 2020
ae94fee
Add a Cohttp implementation to be able to [fetch]/[push]
dinosaure Aug 26, 2020
12f4765
Update the OPAM file of the Git package
dinosaure Aug 26, 2020
9724299
Update the OPAM file of the [git-unix] package
dinosaure Aug 26, 2020
bec5f21
Update the .ocamlformat to depends on ocamlformat.0.15.0
dinosaure Aug 26, 2020
83e1a56
Update dune-project file to add (implicit_transitive_deps false)
dinosaure Aug 26, 2020
2bec336
Add a easy to debug implementation of an HTTP client with [ocurl]
dinosaure Aug 26, 2020
b88d0d6
Apply ocamlformat.0.15.0 over all files
dinosaure Aug 26, 2020
9f23fdd
Update appveyor and remove git-http package
dinosaure Aug 26, 2020
1d3d5d9
Add new package into appveyor CI
dinosaure Aug 26, 2020
0ec12a8
Add stdlib-shims as a dependency to be compatible with OCaml 4.07.0
dinosaure Aug 26, 2020
e6ef527
Update conduit to fix appveyor compilation
dinosaure Aug 26, 2020
7bf1a1c
Test git and git-unix with appveyor
dinosaure Aug 27, 2020
70ea0cb
Update Travis CI script
dinosaure Aug 27, 2020
3709956
Test on git-index is a part of git-unix package
dinosaure Aug 27, 2020
6b8f40c
Add bos as a dependency of git-unix
dinosaure Aug 27, 2020
edf62fa
Missing an Unix.close when we compute the hash of a file.
dinosaure Sep 1, 2020
b443252
Use fpath to normalize path on Windows
dinosaure Sep 1, 2020
05ade14
Use open_in_bin instead open_in (Windows)
dinosaure Sep 1, 2020
11b9b7b
Use open_out_bin instead open_out (Windows)
dinosaure Sep 1, 2020
5656517
Use open_in_bin/in_channel_length to compute hash of a file (Windows)
dinosaure Sep 1, 2020
a9799c7
Ensure to rename to a new file (Windows)
dinosaure Sep 1, 2020
4e2b850
Invalid reference with | character (Windows)
dinosaure Sep 1, 2020
50b8351
Invalid reference with < and > characters (Windows)
dinosaure Sep 1, 2020
d2aa056
Delete useless Fmt.epr to debug
dinosaure Sep 1, 2020
340f288
Relocalizable git-index's tests
dinosaure Sep 1, 2020
23c896b
Fix timespec given by Unix.stat
dinosaure Sep 1, 2020
21f5d26
Run tests about git-index only on unix
dinosaure Sep 2, 2020
8350f44
Apply ocamlformat.0.15.0 on few files
dinosaure Sep 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version=0.15.0
module-item-spacing=compact
break-struct=natural
break-infix=fit-or-vertical
parens-tuple=multi-line-only
wrap-comments=false
break-collection-expressions=wrap
version=0.14.2
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.t
script: bash -ex .travis-opam.sh
env:
global:
- PINS="git.dev:. git-http.dev:. git-unix.dev:. git-mirage.dev:."
- PINS="carton.dev:. carton-lwt.dev:. carton-git.dev:. nss.dev:. git.dev:. git-unix.dev:. git-mirage.dev:."
matrix:
- OCAML_VERSION=4.07 PACKAGE="git.dev"
- OCAML_VERSION=4.08 PACKAGE="git.dev"
- OCAML_VERSION=4.09 PACKAGE="git.dev"
- OCAML_VERSION=4.07 PACKAGE="git-unix.dev"
- OCAML_VERSION=4.07 PACKAGE="git-unix.dev"
- OCAML_VERSION=4.07 PACKAGE="git-mirage.dev"
- OCAML_VERSION=4.07 PACKAGE="git.dev" REVDEPS=*
- OCAML_VERSION=4.10 PACKAGE="git.dev"
- OCAML_VERSION=4.08 PACKAGE="git-unix.dev"
- OCAML_VERSION=4.08 PACKAGE="git-unix.dev"
- OCAML_VERSION=4.08 PACKAGE="git.dev" REVDEPS=*
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ environment:
FORK_USER: ocaml
FORK_BRANCH: master
CYG_ROOT: C:\cygwin64
OPAM_SWITCH: 4.07.0+mingw64c
PINS: "git.dev:. git-http.dev:. git-unix.dev:. git-mirage.dev:."
OPAM_SWITCH: 4.08.1+mingw64c
PINS: "carton.dev:. carton-lwt.dev:. carton-git.dev:. nss.dev:. git.dev:. git-unix.dev:. git-mirage.dev:."
matrix:
- PACKAGE: "git-mirage.dev"
- PACKAGE: "git.dev"
- PACKAGE: "git-unix.dev"

install:
Expand Down
96 changes: 96 additions & 0 deletions bench/bench_pack.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
module Unix_scheduler = Carton.Make (struct type 'a t = 'a end)
open Unix_scheduler

let bomb_pack = "../test/carton/bomb.pack"
let bomb_idx = "../test/carton/bomb.idx"

let scheduler =
{ Carton.bind = (fun x f -> f (prj x)); Carton.return = (fun x -> inj x) }

let map fd ~pos len =
let { Unix.LargeFile.st_size; _ } = Unix.LargeFile.fstat fd in
let len =
if Int64.of_int len <= Int64.sub st_size pos then len
else Int64.(to_int (sub st_size pos))
in
let res =
Unix.map_file fd ~pos Bigarray.char Bigarray.c_layout false [| len |]
in
let res = Bigarray.array1_of_genarray res in
inj res

let fd = Unix.openfile bomb_pack Unix.[ O_RDONLY ] 0o644
let () = at_exit (fun () -> Unix.close fd)

let index =
let tbl = Hashtbl.create 0x100 in

let fd = Unix.openfile bomb_idx Unix.[ O_RDONLY ] 0o644 in
let st = Unix.fstat fd in
let payload = prj (map fd ~pos:0L st.Unix.st_size) in
Unix.close fd;

let idx =
Carton.Dec.Idx.make payload ~uid_ln:Digestif.SHA1.digest_size
~uid_rw:Digestif.SHA1.to_raw_string ~uid_wr:Digestif.SHA1.of_raw_string
in
let f ~uid ~offset ~crc:_ = Hashtbl.add tbl uid offset in
Carton.Dec.Idx.iter ~f idx;
tbl

let z = De.bigstring_create De.io_buffer_size
let w = De.make_window ~bits:15
let allocate _ = w

let pack =
Carton.Dec.make fd ~z ~allocate ~uid_ln:Digestif.SHA1.digest_size
~uid_rw:Digestif.SHA1.of_raw_string (fun uid -> Hashtbl.find index uid)

let ( >>= ) = scheduler.Carton.bind
let return = scheduler.Carton.return
let uid_0 = Digestif.SHA1.of_hex "7af99c9e7d4768fa681f4fe4ff61259794cf719b"
let uid_1 = Digestif.SHA1.of_hex "d9513477b01825130c48c4bebed114c4b2d50401"

let load uid =
Carton.Dec.weight_of_uid scheduler ~map pack ~weight:Carton.Dec.null uid
>>= fun weight ->
let raw = Carton.Dec.make_raw ~weight in
Carton.Dec.of_uid scheduler ~map pack raw uid >>= fun _ -> return ()

let fn_map =
Benchmark.V (fun () -> ignore (prj (map fd ~pos:10L (1024 * 1024))))

let fn_load_0 = Benchmark.V (fun () -> ignore (prj (load uid_0)))
let fn_load_1 = Benchmark.V (fun () -> ignore (prj (load uid_1)))
let s x = Mtime.Span.of_uint64_ns (Int64.mul (Int64.of_int x) 1_000_000_000L)

let run fn_load title =
let (Benchmark.V fn) = fn_load in
let _ = fn () in
let samples_map = Benchmark.run (s 8) fn_map in
let samples_load = Benchmark.run (s 8) fn_load in

match
( Linear_algebra.ols
(fun m -> m.(1))
[| (fun m -> m.(0)); (fun _ -> 1.) |]
samples_map,
Linear_algebra.ols
(fun m -> m.(1))
[| (fun m -> m.(0)); (fun _ -> 1.) |]
samples_load )
with
| Ok (estimate_map, r_map), Ok (estimate_load, r_load) ->
Fmt.pr "%15.2fns (r²: %f) [map syscall].\n%!" estimate_map.(0) r_map;
Fmt.pr "%15.2fns (r²: %f) [load %s].\n%!" estimate_load.(0) r_load title
| Error (`Msg err), _ | _, Error (`Msg err) ->
Fmt.epr "%s: %s.\n%!" Sys.argv.(0) err

let () =
match Sys.argv with
| [| _; "0" |] -> run fn_load_0 "commit (0 delta)"
| [| _; "1" |] -> run fn_load_1 "tree (1 delta)"
| _ ->
Fmt.epr "%s [0|1].\n" Sys.argv.(0);
Fmt.epr "0 commit (0 delta).\n%!";
Fmt.epr "1 tree (1 delta).\n%!"
61 changes: 61 additions & 0 deletions bench/benchmark.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
external tick : unit -> (int64[@unboxed]) = "none" "get_tick" [@@noalloc]
external now : unit -> (int64[@unboxed]) = "none" "get_now" [@@noalloc]

type t = V : (unit -> 'a) -> t

let stabilize_garbage_collector () =
let rec go limit last_heap_live_words =
if limit <= 0 then
failwith "Unable to stabilize the number of live words in the heap";
Gc.compact ();
let stat = Gc.stat () in
if stat.Gc.live_words <> last_heap_live_words then
go (pred limit) stat.Gc.live_words
in
go 10 0

let runnable f i =
for _ = 1 to i do
ignore @@ Sys.opaque_identity (f ())
done
[@@inline]

let samples = 1000

let exceeded_allowed_time allowed_time_span t =
let t' = Mtime.of_uint64_ns (now ()) in
Mtime.Span.compare (Mtime.span t t') allowed_time_span > 0

let run quota t =
let idx = ref 0 in
let run = ref 0 in
let (V fn) = t in

let m = Array.create_float (samples * 2) in

stabilize_garbage_collector ();
let init_time = Mtime.of_uint64_ns (now ()) in

while (not (exceeded_allowed_time quota init_time)) && !idx < samples do
let current_run = !run in
let current_idx = !idx in

let time_0 = now () in

runnable fn current_run;

let time_1 = now () in

m.((current_idx * 2) + 0) <- float_of_int current_run;
m.((current_idx * 2) + 1) <- Int64.to_float (Int64.sub time_1 time_0);

let next =
(max : int -> int -> int)
(int_of_float (float_of_int current_run *. 1.01))
(succ current_run)
in
run := next;
incr idx
done;

Array.init samples (fun i -> [| m.((i * 2) + 0); m.((i * 2) + 1) |])
19 changes: 19 additions & 0 deletions bench/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(executable
(name bench_pack)
(libraries bigstringaf mtime fmt decompress.de decompress.zl digestif.c
bigarray-compat carton unix)
(foreign_stubs
(language c)
(names rdtsc)))

(rule
(alias runbench)
(package carton)
(deps
(:bench bench_pack.exe)
../test/carton/bomb.idx
../test/carton/bomb.pack)
(action
(progn
(run %{bench} 0)
(run %{bench} 1))))
128 changes: 128 additions & 0 deletions bench/linear_algebra.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
(* Code under Apache License 2.0 - Jane Street Group, LLC <opensource@janestreet.com> *)

let col_norm a column =
let acc = ref 0. in
for i = 0 to Array.length a - 1 do
let entry = a.(i).(column) in
acc := !acc +. (entry *. entry)
done;
sqrt !acc

let col_inner_prod t j1 j2 =
let acc = ref 0. in
for i = 0 to Array.length t - 1 do
acc := !acc +. (t.(i).(j1) *. t.(i).(j2))
done;
!acc

let qr_in_place a =
let m = Array.length a in
if m = 0 then [||], [||]
else
let n = Array.length a.(0) in
let r = Array.make_matrix n n 0. in
for j = 0 to n - 1 do
let alpha = col_norm a j in
r.(j).(j) <- alpha;
let one_over_alpha = 1. /. alpha in
for i = 0 to m - 1 do
a.(i).(j) <- a.(i).(j) *. one_over_alpha
done;
for j2 = j + 1 to n - 1 do
let c = col_inner_prod a j j2 in
r.(j).(j2) <- c;
for i = 0 to m - 1 do
a.(i).(j2) <- a.(i).(j2) -. (c *. a.(i).(j))
done
done
done;
a, r

let qr ?(in_place = false) a =
let a = if in_place then a else Array.map Array.copy a in
qr_in_place a

let mul_mv ?(trans = false) a x =
let rows = Array.length a in
if rows = 0 then [||]
else
let cols = Array.length a.(0) in
let m, n, get =
if trans then
let get i j = a.(j).(i) in
cols, rows, get
else
let get i j = a.(i).(j) in
rows, cols, get
in
if n <> Array.length x then failwith "Dimension mismatch";
let result = Array.make m 0. in
for i = 0 to m - 1 do
let v, _ =
Array.fold_left
(fun (acc, j) x -> acc +. (get i j *. x), succ j)
(0., 0) x
in
result.(i) <- v
done;
result

let is_nan v = match classify_float v with FP_nan -> true | _ -> false
let error_msg msg = Error (`Msg msg)

let triu_solve r b =
let m = Array.length b in
if m <> Array.length r then
error_msg
"triu_solve R b requires R to be square with same number of rows as b"
else if m = 0 then Ok [||]
else if m <> Array.length r.(0) then
error_msg "triu_solve R b requires R to be a square"
else
let sol = Array.copy b in
for i = m - 1 downto 0 do
sol.(i) <- sol.(i) /. r.(i).(i);
for j = 0 to i - 1 do
sol.(j) <- sol.(j) -. (r.(j).(i) *. sol.(i))
done
done;
if Array.exists is_nan sol then error_msg "triu_solve detected NaN result"
else Ok sol

let ols ?(in_place = false) a b =
let q, r = qr ~in_place a in
triu_solve r (mul_mv ~trans:true q b)

let make_lr_inputs responder predictors m =
( Array.init (Array.length m) (fun i ->
Array.map (fun a -> a m.(i)) predictors),
Array.init (Array.length m) (fun i -> responder m.(i)) )

let r_square m responder predictors r =
let predictors_matrix, responder_vector =
make_lr_inputs responder predictors m
in
let sum_responder = Array.fold_left ( +. ) 0. responder_vector in
let mean = sum_responder /. float (Array.length responder_vector) in
let tot_ss = ref 0. in
let res_ss = ref 0. in
let predicted i =
let x = ref 0. in
for j = 0 to Array.length r - 1 do
x := !x +. (predictors_matrix.(i).(j) *. r.(j))
done;
!x
in
for i = 0 to Array.length responder_vector - 1 do
tot_ss := !tot_ss +. ((responder_vector.(i) -. mean) ** 2.);
res_ss := !res_ss +. ((responder_vector.(i) -. predicted i) ** 2.)
done;
1. -. (!res_ss /. !tot_ss)

let ols responder predictors m =
let matrix, vector = make_lr_inputs responder predictors m in
match ols ~in_place:true matrix vector with
| Ok estimates ->
let r_square = r_square m responder predictors estimates in
Ok (estimates, r_square)
| Error _ as err -> err
33 changes: 33 additions & 0 deletions bench/rdtsc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdint.h>
#include <time.h>

#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/fail.h>

#ifndef __unused
#define __unused(x) x __attribute((unused))
#endif
#define __unit() value __unused(unit)

uint64_t
get_now(__unit ())
{
struct timespec ts;

clock_gettime(CLOCK_MONOTONIC, &ts);

return ((uint64_t) ts.tv_sec
* (uint64_t) 1000000000LL
+ (uint64_t) ts.tv_nsec);
}

uint64_t
get_tick(__unit ())
{
unsigned hi, lo;
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));

return (((unsigned long long) lo) | (((unsigned long long) hi) << 32));
}
Loading