Commit f767131 1 parent 3ea8caf commit f767131 Copy full SHA for f767131
File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -70,12 +70,26 @@ let build_filter = function
70
70
| exception Not_found -> false
71
71
end
72
72
73
+ let shuffle xs =
74
+ let xs = Array. of_list xs in
75
+ let state = Random.State. make_self_init () in
76
+ let n = Array. length xs in
77
+ for i = 0 to n - 2 do
78
+ let j = Random.State. int state (n - i) + i in
79
+ let t = xs.(i) in
80
+ xs.(i) < - xs.(j);
81
+ xs.(j) < - t
82
+ done ;
83
+ Array. to_list xs
84
+
73
85
let run ~benchmarks ?(budgetf = 0.025 ) ?(filters = [] ) ?(debug = false )
74
- ?(output = `JSON ) ?(argv = Sys. argv) ?(flush = true ) () =
86
+ ?(output = `JSON ) ?(argv = Sys. argv) ?(flush = true ) ?(randomize = true ) ()
87
+ =
75
88
let budgetf = ref budgetf in
76
89
let filters = ref filters in
77
90
let debug = ref debug in
78
91
let output = ref output in
92
+ let randomize = ref randomize in
79
93
80
94
let rec specs =
81
95
[
@@ -119,7 +133,14 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false)
119
133
`List
120
134
(benchmarks
121
135
|> List. filter (build_filter ! filters)
122
- |> List. map (run_benchmark ~debug: ! debug ~budgetf: ! budgetf)) );
136
+ |> (if ! randomize then shuffle else Fun. id)
137
+ |> List. map (run_benchmark ~debug: ! debug ~budgetf: ! budgetf)
138
+ |> List. sort (fun l r ->
139
+ let name_of = function
140
+ | `Assoc (("name" , `String name ) :: _ ) -> name
141
+ | _ -> failwith " bug"
142
+ in
143
+ String. compare (name_of l) (name_of r))) );
123
144
]
124
145
in
125
146
Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ module Cmd : sig
180
180
?output : output ->
181
181
?argv : string array ->
182
182
?flush : bool ->
183
+ ?randomize : bool ->
183
184
unit ->
184
185
unit
185
186
(* * [run ~benchmarks ()] interprets command line arguments and runs the
@@ -205,6 +206,9 @@ module Cmd : sig
205
206
- [~flush]: Whether to flush the standard output after writing it.
206
207
Defaults to [true].
207
208
209
+ - [~randomize]: Whether to randomize the order of suites or not. Defaults
210
+ to [true].
211
+
208
212
Command line arguments take precedence over the optional arguments. In
209
213
other words, you can specify the optional arguments to give defaults for
210
214
the benchmark executable. *)
You can’t perform that action at this time.
0 commit comments