|
| 1 | +(* dune exec bench/basic/benchTuple4.exe -- -a *) |
| 2 | + |
| 3 | +open Benchmark |
| 4 | +open Benchmark.Tree |
| 5 | + |
| 6 | + |
| 7 | +let () = |
| 8 | + let exists0 = |
| 9 | + let open Batteries in |
| 10 | + let to_list x = Tuple4.enum x |> List.of_enum |> List.filter_map identity in |
| 11 | + let f g = g identity % to_list in |
| 12 | + List.(f exists) |
| 13 | + in |
| 14 | + |
| 15 | + let exists1 = function |
| 16 | + | (Some true, _, _, _) |
| 17 | + | (_, Some true, _, _) |
| 18 | + | (_, _, Some true, _) |
| 19 | + | (_, _, _, Some true) -> |
| 20 | + true |
| 21 | + | _ -> |
| 22 | + false |
| 23 | + in |
| 24 | + |
| 25 | + let exists2 (a, b, c, d) = a = Some true || b = Some true || c = Some true || d = Some true in |
| 26 | + |
| 27 | + |
| 28 | + register ( |
| 29 | + "exists" @>>> [ |
| 30 | + "all None" @> lazy ( |
| 31 | + let args = (None, None, None, None) in |
| 32 | + throughputN 1 [ |
| 33 | + ("0", exists0, args); |
| 34 | + ("1", exists1, args); |
| 35 | + ("2", exists2, args); |
| 36 | + ] |
| 37 | + ); |
| 38 | + "all Some true" @> lazy ( |
| 39 | + let args = (Some true, Some true, Some true, Some true) in |
| 40 | + throughputN 1 [ |
| 41 | + ("0", exists0, args); |
| 42 | + ("1", exists1, args); |
| 43 | + ("2", exists2, args); |
| 44 | + ] |
| 45 | + ); |
| 46 | + "all Some false" @> lazy ( |
| 47 | + let args = (Some false, Some false, Some false, Some false) in |
| 48 | + throughputN 1 [ |
| 49 | + ("0", exists0, args); |
| 50 | + ("1", exists1, args); |
| 51 | + ("2", exists2, args); |
| 52 | + ] |
| 53 | + ); |
| 54 | + "all None except last Some true" @> lazy ( |
| 55 | + let args = (None, None, None, Some true) in |
| 56 | + throughputN 1 [ |
| 57 | + ("0", exists0, args); |
| 58 | + ("1", exists1, args); |
| 59 | + ("2", exists2, args); |
| 60 | + ] |
| 61 | + ); |
| 62 | + "all Some false except last Some true" @> lazy ( |
| 63 | + let args = (Some false, Some false, Some false, Some true) in |
| 64 | + throughputN 1 [ |
| 65 | + ("0", exists0, args); |
| 66 | + ("1", exists1, args); |
| 67 | + ("2", exists2, args); |
| 68 | + ] |
| 69 | + ); |
| 70 | + ] |
| 71 | + ) |
| 72 | + |
| 73 | + |
| 74 | +let () = |
| 75 | + let for_all0 = |
| 76 | + let open Batteries in |
| 77 | + let to_list x = Tuple4.enum x |> List.of_enum |> List.filter_map identity in |
| 78 | + let f g = g identity % to_list in |
| 79 | + List.(f for_all) |
| 80 | + in |
| 81 | + |
| 82 | + let for_all1 = function |
| 83 | + | (Some false, _, _, _) |
| 84 | + | (_, Some false, _, _) |
| 85 | + | (_, _, Some false, _) |
| 86 | + | (_, _, _, Some false) -> |
| 87 | + false |
| 88 | + | _ -> |
| 89 | + true |
| 90 | + in |
| 91 | + |
| 92 | + let for_all2 (a, b, c, d) = not (a = Some false || b = Some false || c = Some false || d = Some false) in |
| 93 | + |
| 94 | + |
| 95 | + register ( |
| 96 | + "for_all" @>>> [ |
| 97 | + "all None" @> lazy ( |
| 98 | + let args = (None, None, None, None) in |
| 99 | + throughputN 1 [ |
| 100 | + ("0", for_all0, args); |
| 101 | + ("1", for_all1, args); |
| 102 | + ("2", for_all2, args); |
| 103 | + ] |
| 104 | + ); |
| 105 | + "all Some true" @> lazy ( |
| 106 | + let args = (Some true, Some true, Some true, Some true) in |
| 107 | + throughputN 1 [ |
| 108 | + ("0", for_all0, args); |
| 109 | + ("1", for_all1, args); |
| 110 | + ("2", for_all2, args); |
| 111 | + ] |
| 112 | + ); |
| 113 | + "all Some false" @> lazy ( |
| 114 | + let args = (Some false, Some false, Some false, Some false) in |
| 115 | + throughputN 1 [ |
| 116 | + ("0", for_all0, args); |
| 117 | + ("1", for_all1, args); |
| 118 | + ("2", for_all2, args); |
| 119 | + ] |
| 120 | + ); |
| 121 | + "all None except last Some false" @> lazy ( |
| 122 | + let args = (None, None, None, Some false) in |
| 123 | + throughputN 1 [ |
| 124 | + ("0", for_all0, args); |
| 125 | + ("1", for_all1, args); |
| 126 | + ("2", for_all2, args); |
| 127 | + ] |
| 128 | + ); |
| 129 | + "all Some true except last Some false" @> lazy ( |
| 130 | + let args = (Some true, Some true, Some true, Some false) in |
| 131 | + throughputN 1 [ |
| 132 | + ("0", for_all0, args); |
| 133 | + ("1", for_all1, args); |
| 134 | + ("2", for_all2, args); |
| 135 | + ] |
| 136 | + ); |
| 137 | + ] |
| 138 | + ) |
| 139 | + |
| 140 | +let () = |
| 141 | + run_global () |
0 commit comments