Source file bench_absolute.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
open! Core
type t = File_path.Absolute.t [@@deriving quickcheck, sexp, sexp_grammar]
let arg_type = File_path.Absolute.arg_type
let root = File_path.Absolute.root
include (
File_path.Absolute :
Identifiable.S
with type t := t
and type comparator_witness = File_path.Absolute.comparator_witness)
let%bench_fun "equal =" =
let x = Sys.opaque_identity (of_string "/foo/bar/baz") in
let y = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> equal x y
;;
let%bench_fun "equal <>" =
let x = Sys.opaque_identity root in
let y = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> equal x y
;;
let%bench_fun "compare =" =
let x = Sys.opaque_identity root in
let y = Sys.opaque_identity root in
fun () -> compare x y
;;
let%bench_fun "compare <" =
let x = Sys.opaque_identity root in
let y = Sys.opaque_identity (of_string "/.") in
fun () -> compare x y
;;
let%bench_fun "compare >" =
let x = Sys.opaque_identity (of_string "/.") in
let y = Sys.opaque_identity root in
fun () -> compare x y
;;
let%bench_fun "of_string, canonical" =
let string = Sys.opaque_identity "/foo/bar/baz" in
fun () -> of_string string
;;
let%bench_fun "of_string, non-canonical" =
let string = Sys.opaque_identity "/foo//bar/baz/" in
fun () -> of_string string
;;
let%bench_fun "to_string" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> to_string t
;;
let%bench_fun "t_of_sexp, canonical" =
let string = Sys.opaque_identity (Sexp.Atom "/foo/bar/baz") in
fun () -> t_of_sexp string
;;
let%bench_fun "t_of_sexp, non-canonical" =
let string = Sys.opaque_identity (Sexp.Atom "/foo//bar/baz/") in
fun () -> t_of_sexp string
;;
let%bench_fun "sexp_of_t" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> sexp_of_t t
;;
module Expert = struct
let unchecked_of_canonical_string =
File_path.Absolute.Expert.unchecked_of_canonical_string
;;
let%bench_fun "unchecked_of_canonical_string" =
let string = Sys.opaque_identity "/foo/bar/baz" in
fun () -> unchecked_of_canonical_string string
;;
end
let invariant = File_path.Absolute.invariant
let%bench_fun "invariant" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> invariant t
;;
let basename = File_path.Absolute.basename
let%bench_fun "basename, some" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> basename t
;;
let%bench_fun "basename, none" =
let t = Sys.opaque_identity root in
fun () -> basename t
;;
let basename_exn = File_path.Absolute.basename_exn
let%bench_fun "basename_exn" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> basename_exn t
;;
let basename_or_error = File_path.Absolute.basename_or_error
let%bench_fun "basename_or_error" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> basename_or_error t
;;
let basename_defaulting_to_dot = File_path.Absolute.basename_defaulting_to_dot
let%bench_fun "basename_defaulting_to_dot, name" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> basename_defaulting_to_dot t
;;
let%bench_fun "basename_defaulting_to_dot, dot" =
let t = Sys.opaque_identity root in
fun () -> basename_defaulting_to_dot t
;;
let dirname = File_path.Absolute.dirname
let%bench_fun "dirname, some" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> dirname t
;;
let%bench_fun "dirname, none" =
let t = Sys.opaque_identity root in
fun () -> dirname t
;;
let dirname_exn = File_path.Absolute.dirname_exn
let%bench_fun "dirname_exn" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> dirname_exn t
;;
let dirname_or_error = File_path.Absolute.dirname_or_error
let%bench_fun "dirname_or_error" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> dirname_or_error t
;;
let dirname_defaulting_to_root = File_path.Absolute.dirname_defaulting_to_root
let%bench_fun "dirname_defaulting_to_root, dir" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> dirname_defaulting_to_root t
;;
let%bench_fun "dirname_defaulting_to_root, root" =
let t = Sys.opaque_identity root in
fun () -> dirname_defaulting_to_root t
;;
let dirname_and_basename = File_path.Absolute.dirname_and_basename
let%bench_fun "dirname_and_basename, some" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> dirname_and_basename t
;;
let%bench_fun "dirname_and_basename, none" =
let t = Sys.opaque_identity root in
fun () -> dirname_and_basename t
;;
let append_to_basename_exn = File_path.Absolute.append_to_basename_exn
let%bench_fun "append_to_basename_exn, empty" =
let t = Sys.opaque_identity (of_string "/foo/bar") in
let suffix = Sys.opaque_identity "" in
fun () -> append_to_basename_exn t suffix
;;
let%bench_fun "append_to_basename_exn, nonempty" =
let t = Sys.opaque_identity (of_string "/foo/bar") in
let suffix = Sys.opaque_identity ".baz" in
fun () -> append_to_basename_exn t suffix
;;
let append_part = File_path.Absolute.append_part
let%bench_fun "append_part, root" =
let t = Sys.opaque_identity root in
let suffix = Sys.opaque_identity (File_path.Part.of_string "foo") in
fun () -> append_part t suffix
;;
let%bench_fun "append_part, dir" =
let t = Sys.opaque_identity (of_string "/foo/bar") in
let suffix = Sys.opaque_identity (File_path.Part.of_string "baz") in
fun () -> append_part t suffix
;;
let is_prefix = File_path.Absolute.is_prefix
let%bench_fun "is_prefix, true" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let prefix = Sys.opaque_identity (of_string "/foo/bar") in
fun () -> is_prefix t ~prefix
;;
let%bench_fun "is_prefix, false" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let prefix = Sys.opaque_identity (of_string "/foobie") in
fun () -> is_prefix t ~prefix
;;
let chop_prefix = File_path.Absolute.chop_prefix
let%bench_fun "chop_prefix, some" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let prefix = Sys.opaque_identity (of_string "/foo/bar") in
fun () -> chop_prefix t ~prefix
;;
let%bench_fun "chop_prefix, none" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let prefix = Sys.opaque_identity (of_string "/foobie") in
fun () -> chop_prefix t ~prefix
;;
let chop_prefix_exn = File_path.Absolute.chop_prefix_exn
let%bench_fun "chop_prefix_exn" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let prefix = Sys.opaque_identity (of_string "/foo/bar") in
fun () -> chop_prefix_exn t ~prefix
;;
let chop_prefix_or_error = File_path.Absolute.chop_prefix_or_error
let%bench_fun "chop_prefix_or_error" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let prefix = Sys.opaque_identity (of_string "/foo/bar") in
fun () -> chop_prefix_or_error t ~prefix
;;
let is_suffix = File_path.Absolute.is_suffix
let%bench_fun "is_suffix, true" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> is_suffix t ~suffix
;;
let%bench_fun "is_suffix, false" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "barbie") in
fun () -> is_suffix t ~suffix
;;
let chop_suffix = File_path.Absolute.chop_suffix
let%bench_fun "chop_suffix, some" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> chop_suffix t ~suffix
;;
let%bench_fun "chop_suffix, none" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "barbie") in
fun () -> chop_suffix t ~suffix
;;
let chop_suffix_exn = File_path.Absolute.chop_suffix_exn
let%bench_fun "chop_suffix_exn" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> chop_suffix_exn t ~suffix
;;
let chop_suffix_or_error = File_path.Absolute.chop_suffix_or_error
let%bench_fun "chop_suffix_or_error" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> chop_suffix_or_error t ~suffix
;;
let chop_suffix_if_exists = File_path.Absolute.chop_suffix_if_exists
let%bench_fun "chop_suffix_if_exists" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> chop_suffix_if_exists t ~suffix
;;
let append = File_path.Absolute.append
let%bench_fun "append, root" =
let prefix = Sys.opaque_identity root in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> append prefix suffix
;;
let%bench_fun "append, dir" =
let prefix = Sys.opaque_identity (of_string "/foo") in
let suffix = Sys.opaque_identity (File_path.Relative.of_string "bar/baz") in
fun () -> append prefix suffix
;;
let number_of_parts = File_path.Absolute.number_of_parts
let%bench_fun "number_of_parts, root" =
let t = Sys.opaque_identity root in
fun () -> number_of_parts t
;;
let%bench_fun "number_of_parts, compound" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> number_of_parts t
;;
let to_parts = File_path.Absolute.to_parts
let%bench_fun "to_parts, root" =
let t = Sys.opaque_identity root in
fun () -> to_parts t
;;
let%bench_fun "to_parts, dir" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> to_parts t
;;
let of_parts = File_path.Absolute.of_parts
let%bench_fun "of_parts" =
let parts =
Sys.opaque_identity
[ File_path.Part.of_string "foo"
; File_path.Part.of_string "bar"
; File_path.Part.of_string "baz"
]
in
fun () -> of_parts parts
;;
let simplify_dot = File_path.Absolute.simplify_dot
let%bench_fun "simplify_dot, unchanged" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> simplify_dot t
;;
let%bench_fun "simplify_dot, changed" =
let t = Sys.opaque_identity (of_string "/foo/./bar/baz/.") in
fun () -> simplify_dot t
;;
let simplify_dot_and_dot_dot_naively = File_path.Absolute.simplify_dot_and_dot_dot_naively
let%bench_fun "simplify_dot_and_dot_dot_naively, unchanged" =
let t = Sys.opaque_identity (of_string "/foo/bar/baz") in
fun () -> simplify_dot_and_dot_dot_naively t
;;
let%bench_fun "simplify_dot_and_dot_dot_naively, changed" =
let t = Sys.opaque_identity (of_string "/foo/quux/../bar/baz/.") in
fun () -> simplify_dot_and_dot_dot_naively t
;;