Skip to content

Commit

Permalink
Avoid include of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Oct 13, 2024
1 parent 06e7bd0 commit 7c85236
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions lib/cmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ let duplicate kind name x _ =
(name x |> replace_non_breaking_spaces))

let print_diff base next =
List.zip_by
List_ext.zip_by
~duplicate:(duplicate "benchmark" Benchmark.name)
String.compare Benchmark.name base next
|> List.iter @@ fun ((base : Benchmark.t), (next : Benchmark.t)) ->
Printf.printf "%s:\n" base.name;
let zipped =
List.zip_by
List_ext.zip_by
~duplicate:(duplicate "metric" Metric.name)
String.compare Metric.name base.metrics next.metrics
in
Expand Down Expand Up @@ -159,7 +159,7 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false)
match base_results with
| [] -> Fun.id
| results ->
let (module S) = Set.make String.compare in
let (module S) = Set_ext.make String.compare in
let names = results |> List.map Benchmark.name |> S.of_list in
List.filter (fun (name, _) -> S.mem name names)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/countdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ let non_atomic_set t count =

let rec get t count i =
if i < Array.length t && Array.unsafe_get t i != Array.unsafe_get t 0 then
get t (count + Int.max 0 (Atomic.get (Array.unsafe_get t i))) (i + 1)
get t (count + Int_ext.max 0 (Atomic.get (Array.unsafe_get t i))) (i + 1)
else count

let[@inline] get t = get t (Int.max 0 (Atomic.get (Array.unsafe_get t 0))) 1
let[@inline] get t = get t (Int_ext.max 0 (Atomic.get (Array.unsafe_get t 0))) 1

let rec alloc t ~batch i =
if i < Array.length t then
let c = Array.unsafe_get t i in
if 0 < Atomic.get c then
let n = Atomic.fetch_and_add c (-batch) in
if 0 < n then Int.min n batch else alloc t ~batch (i + 1)
if 0 < n then Int_ext.min n batch else alloc t ~batch (i + 1)
else alloc t ~batch (i + 1)
else 0

let[@inline] alloc t ~domain_index ~batch =
let c = Array.unsafe_get t domain_index in
if 0 < Atomic.get c then
let n = Atomic.fetch_and_add c (-batch) in
if 0 < n then Int.min n batch else alloc t ~batch 0
if 0 < n then Int_ext.min n batch else alloc t ~batch 0
else alloc t ~batch 0
2 changes: 1 addition & 1 deletion lib/data.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Option.Syntax
open Option_ext.Syntax

module Trend = struct
type t = [ `Lower_is_better | `Higher_is_better ]
Expand Down
8 changes: 7 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ let () =
(enabled_if
(< %{ocaml_version} 4.13.0))
(action
(copy int.ocaml_4_12.ml int.ml)))
(copy int_ext.ocaml_lt_4_13.ml int_ext.ml)))

(rule
(enabled_if
(>= %{ocaml_version} 4.13.0))
(action
(copy int_ext.ocaml_ge_4_13.ml int_ext.ml)))

(library
(public_name multicore-bench)
Expand Down
4 changes: 0 additions & 4 deletions lib/int.ocaml_4_12.ml

This file was deleted.

2 changes: 2 additions & 0 deletions lib/int_ext.ocaml_ge_4_13.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let min = Int.min
let max = Int.max
2 changes: 2 additions & 0 deletions lib/int_ext.ocaml_lt_4_13.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let min (x : int) (y : int) = if x < y then x else y
let max (x : int) (y : int) = if x < y then y else x
2 changes: 1 addition & 1 deletion lib/json.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Option.Syntax
open Option_ext.Syntax

type t = Yojson.Safe.t

Expand Down
8 changes: 3 additions & 5 deletions lib/list.ml → lib/list_ext.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
include Stdlib.List

let default_duplicate _ _ = invalid_arg "duplicate key"
let default_missing _ _ = None

let zip_by (type k) ?(duplicate = default_duplicate)
?(missing = default_missing) (compare : k -> _) key_of xs ys =
let (module M) = Map.make compare in
let (module M) = Map_ext.make compare in
let to_map xs =
xs
|> fold_left
|> List.fold_left
(fun m x ->
m
|> M.update (key_of x) @@ function
Expand All @@ -24,4 +22,4 @@ let zip_by (type k) ?(duplicate = default_duplicate)
| None, Some y -> missing `L y
| None, None -> None)
(to_map xs) (to_map ys)
|> M.bindings |> map snd
|> M.bindings |> List.map snd
4 changes: 1 addition & 3 deletions lib/map.ml → lib/map_ext.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include Stdlib.Map

let make (type t) (compare : t -> _) =
let (module Elt) = Ordered.make compare in
(module Make (Elt) : Stdlib.Map.S with type key = t)
(module Map.Make (Elt) : Map.S with type key = t)
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/ordered.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ let make (type t) (compare : t -> _) =
type nonrec t = t

let compare = compare
end : Stdlib.Set.OrderedType
end : Set.OrderedType
with type t = t)
4 changes: 1 addition & 3 deletions lib/set.ml → lib/set_ext.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include Stdlib.Set

let make (type t) (compare : t -> _) =
let (module Elt) = Ordered.make compare in
(module Make (Elt) : Stdlib.Set.S with type elt = t)
(module Set.Make (Elt) : Set.S with type elt = t)
2 changes: 1 addition & 1 deletion lib/times.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let record (type a) ~budgetf ~n_domains ?(ensure_multi_domain = true)
wrap;
results =
Array.init n_domains (fun _ ->
Float.Array.create (Int.max n_runs_min n_runs_max));
Float.Array.create (Int_ext.max n_runs_min n_runs_max));
budget_start = Mtime_clock.elapsed ();
before;
init;
Expand Down
2 changes: 1 addition & 1 deletion lib/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let rec alloc ?(batch = 1000) counter =
let n = Atomic.get counter in
if n = 0 then 0
else
let batch = Int.min n batch in
let batch = Int_ext.min n batch in
if Atomic.compare_and_set counter n (n - batch) then batch
else alloc ~batch counter

Expand Down

0 comments on commit 7c85236

Please sign in to comment.