| 1 | package Bencher::Scenario::SetOperationModules; | ||
| 2 | |||
| 3 | 1 | our $DATE = '2021-05-15'; # DATE | |
| 4 | 1 | our $VERSION = '0.130'; # VERSION | |
| 5 | |||
| 6 | 1 | ▶ | use 5.010001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | our $scenario = { | |
| 11 | summary => 'Benchmark Perl set operation (union, intersection, diff, symmetric diff) modules', | ||
| 12 | modules => { | ||
| 13 | 'List::MoreUtils' => { | ||
| 14 | version => '0.407', # singleton() is available from this version | ||
| 15 | }, | ||
| 16 | }, | ||
| 17 | participants => [ | ||
| 18 | # UNION | ||
| 19 | { | ||
| 20 | tags => ['op:union'], | ||
| 21 | module => 'Array::Utils', | ||
| 22 | function => 'unique', | ||
| 23 | code_template => '&Array::Utils::unique(<set1>, <set2>)', # we use &func instead of func to defeat prototype which confuses some tools | ||
| 24 | }, | ||
| 25 | { | ||
| 26 | tags => ['op:union'], | ||
| 27 | module => 'Set::Scalar', | ||
| 28 | function => 'union', | ||
| 29 | code_template => 'my $s1 = Set::Scalar->new(@{<set1>}); my $s2 = Set::Scalar->new(@{<set2>}); $s1->union($s2)', | ||
| 30 | }, | ||
| 31 | { | ||
| 32 | tags => ['op:union'], | ||
| 33 | fcall_template => 'List::MoreUtils::PP::uniq(@{<set1>}, @{<set2>})', | ||
| 34 | }, | ||
| 35 | { | ||
| 36 | name => 'List::MoreUtils::XS::uniq', | ||
| 37 | tags => ['op:union'], | ||
| 38 | module => 'List::MoreUtils::XS', | ||
| 39 | fcall_template => 'List::MoreUtils::uniq(@{<set1>}, @{<set2>})', | ||
| 40 | }, | ||
| 41 | { | ||
| 42 | tags => ['op:union'], | ||
| 43 | fcall_template => 'Array::Set::set_union(<set1>, <set2>)', | ||
| 44 | }, | ||
| 45 | { | ||
| 46 | tags => ['op:union'], | ||
| 47 | fcall_template => 'Array::Set::Naive::set_union(<set1>, <set2>)', | ||
| 48 | }, | ||
| 49 | { | ||
| 50 | tags => ['op:union'], | ||
| 51 | module => 'Set::Array', | ||
| 52 | function => 'union', | ||
| 53 | code_template => 'my $s1 = Set::Array->new(@{<set1>}); my $s2 = Set::Array->new(@{<set2>}); $s1->union($s2)', | ||
| 54 | }, | ||
| 55 | { | ||
| 56 | tags => ['op:union'], | ||
| 57 | module => 'Array::AsObject', | ||
| 58 | function => 'union', | ||
| 59 | code_template => 'my $s1 = Array::AsObject->new(@{<set1>}); my $s2 = Array::AsObject->new(@{<set2>}); $s1->union($s2, 1)', | ||
| 60 | }, | ||
| 61 | { | ||
| 62 | tags => ['op:union'], | ||
| 63 | module => 'Set::Object', | ||
| 64 | function => 'union', | ||
| 65 | code_template => 'my $s1 = Set::Object->new(@{<set1>}); my $s2 = Set::Object->new(@{<set2>}); $s1->union($s2)', | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | tags => ['op:union'], | ||
| 69 | module => 'Set::Tiny', | ||
| 70 | function => 'union', | ||
| 71 | code_template => 'my $s1 = Set::Tiny->new(@{<set1>}); my $s2 = Set::Tiny->new(@{<set2>}); $s1->union($s2)', | ||
| 72 | }, | ||
| 73 | { | ||
| 74 | tags => ['op:union'], | ||
| 75 | module => 'List::Collection', | ||
| 76 | function => 'union', | ||
| 77 | code_template => '[List::Collection::union(<set1>, <set2>)]', | ||
| 78 | }, | ||
| 79 | |||
| 80 | # SYMDIFF | ||
| 81 | { | ||
| 82 | tags => ['op:symdiff'], | ||
| 83 | module => 'Array::Utils', | ||
| 84 | function => 'array_diff', | ||
| 85 | code_template => '&Array::Utils::array_diff(<set1>, <set2>)', # we use &func instead of func to defeat prototype which confuses some tools | ||
| 86 | }, | ||
| 87 | { | ||
| 88 | tags => ['op:symdiff'], | ||
| 89 | module => 'Set::Scalar', | ||
| 90 | function => 'symmetric_difference', | ||
| 91 | code_template => 'my $s1 = Set::Scalar->new(@{<set1>}); my $s2 = Set::Scalar->new(@{<set2>}); $s1->symmetric_difference($s2)', | ||
| 92 | }, | ||
| 93 | # List::MoreUtils' singleton() can do symmetric difference as long as we | ||
| 94 | # make sure that set1 and set2 do not contain duplicates (which, since | ||
| 95 | # they should be sets, should not) | ||
| 96 | { | ||
| 97 | tags => ['op:symdiff'], | ||
| 98 | fcall_template => 'List::MoreUtils::PP::singleton(@{<set1>}, @{<set2>})', | ||
| 99 | }, | ||
| 100 | { | ||
| 101 | name => 'List::MoreUtils::XS::singleton', | ||
| 102 | tags => ['op:symdiff'], | ||
| 103 | module => 'List::MoreUtils::XS', | ||
| 104 | fcall_template => 'List::MoreUtils::singleton(@{<set1>}, @{<set2>})', | ||
| 105 | }, | ||
| 106 | { | ||
| 107 | tags => ['op:symdiff'], | ||
| 108 | fcall_template => 'Array::Set::set_symdiff(<set1>, <set2>)', | ||
| 109 | }, | ||
| 110 | { | ||
| 111 | tags => ['op:symdiff'], | ||
| 112 | fcall_template => 'Array::Set::Naive::set_symdiff(<set1>, <set2>)', | ||
| 113 | }, | ||
| 114 | { | ||
| 115 | tags => ['op:symdiff'], | ||
| 116 | module => 'Set::Array', | ||
| 117 | function => 'symmetric_difference', | ||
| 118 | code_template => 'my $s1 = Set::Array->new(@{<set1>}); my $s2 = Set::Array->new(@{<set2>}); $s1->symmetric_difference($s2)', | ||
| 119 | }, | ||
| 120 | # Array::AsObject::symmetric_difference's handling of duplicates is | ||
| 121 | # non-standard though, see its doc | ||
| 122 | { | ||
| 123 | tags => ['op:symdiff'], | ||
| 124 | module => 'Array::AsObject', | ||
| 125 | function => 'symmetric_difference', | ||
| 126 | code_template => 'my $s1 = Array::AsObject->new(@{<set1>}); my $s2 = Array::AsObject->new(@{<set2>}); $s1->symmetric_difference($s2)', | ||
| 127 | }, | ||
| 128 | { | ||
| 129 | tags => ['op:symdiff'], | ||
| 130 | module => 'Set::Object', | ||
| 131 | function => 'symmetric_difference', | ||
| 132 | code_template => 'my $s1 = Set::Object->new(@{<set1>}); my $s2 = Set::Object->new(@{<set2>}); $s1->symmetric_difference($s2)', | ||
| 133 | }, | ||
| 134 | { | ||
| 135 | tags => ['op:symdiff'], | ||
| 136 | module => 'Set::Tiny', | ||
| 137 | function => 'symmetric_difference', | ||
| 138 | code_template => 'my $s1 = Set::Tiny->new(@{<set1>}); my $s2 = Set::Tiny->new(@{<set2>}); $s1->symmetric_difference($s2)', | ||
| 139 | }, | ||
| 140 | { | ||
| 141 | tags => ['op:symdiff'], | ||
| 142 | module => 'List::Collection', | ||
| 143 | function => 'complement', | ||
| 144 | code_template => '[List::Collection::complement(<set1>, <set2>)]', | ||
| 145 | }, | ||
| 146 | |||
| 147 | # DIFF | ||
| 148 | { | ||
| 149 | tags => ['op:diff'], | ||
| 150 | module => 'Array::Utils', | ||
| 151 | function => 'array_minus', | ||
| 152 | code_template => '&Array::Utils::array_minus(<set1>, <set2>)', # we use &func instead of func to defeat prototype which confuses some tools | ||
| 153 | }, | ||
| 154 | { | ||
| 155 | tags => ['op:diff'], | ||
| 156 | module => 'Set::Scalar', | ||
| 157 | function => 'difference', | ||
| 158 | code_template => 'my $s1 = Set::Scalar->new(@{<set1>}); my $s2 = Set::Scalar->new(@{<set2>}); $s1->difference($s2)', | ||
| 159 | }, | ||
| 160 | { | ||
| 161 | tags => ['op:diff'], | ||
| 162 | fcall_template => 'Array::Set::set_diff(<set1>, <set2>)', | ||
| 163 | }, | ||
| 164 | { | ||
| 165 | tags => ['op:diff'], | ||
| 166 | fcall_template => 'Array::Set::Naive::set_diff(<set1>, <set2>)', | ||
| 167 | }, | ||
| 168 | { | ||
| 169 | tags => ['op:diff'], | ||
| 170 | module => 'Set::Array', | ||
| 171 | function => 'difference', | ||
| 172 | code_template => 'my $s1 = Set::Array->new(@{<set1>}); my $s2 = Set::Array->new(@{<set2>}); $s1->difference($s2)', | ||
| 173 | }, | ||
| 174 | # Array::AsObject::difference's handling of duplicates is non-standard | ||
| 175 | # though, see its doc | ||
| 176 | { | ||
| 177 | tags => ['op:diff'], | ||
| 178 | module => 'Array::AsObject', | ||
| 179 | function => 'difference', | ||
| 180 | code_template => 'my $s1 = Array::AsObject->new(@{<set1>}); my $s2 = Array::AsObject->new(@{<set2>}); $s1->difference($s2)', | ||
| 181 | }, | ||
| 182 | { | ||
| 183 | tags => ['op:diff'], | ||
| 184 | module => 'Set::Object', | ||
| 185 | function => 'difference', | ||
| 186 | code_template => 'my $s1 = Set::Object->new(@{<set1>}); my $s2 = Set::Object->new(@{<set2>}); $s1->difference($s2)', | ||
| 187 | }, | ||
| 188 | { | ||
| 189 | tags => ['op:diff'], | ||
| 190 | module => 'Set::Tiny', | ||
| 191 | function => 'difference', | ||
| 192 | code_template => 'my $s1 = Set::Tiny->new(@{<set1>}); my $s2 = Set::Tiny->new(@{<set2>}); $s1->difference($s2)', | ||
| 193 | }, | ||
| 194 | { | ||
| 195 | tags => ['op:diff'], | ||
| 196 | module => 'List::Collection', | ||
| 197 | function => 'subtract', | ||
| 198 | code_template => '[List::Collection::subtract(<set1>, <set2>)]', | ||
| 199 | }, | ||
| 200 | |||
| 201 | # INTERSECT | ||
| 202 | { | ||
| 203 | tags => ['op:intersect'], | ||
| 204 | module => 'Array::Utils', | ||
| 205 | function => 'intersect', | ||
| 206 | code_template => '&Array::Utils::intersect(<set1>, <set2>)', # we use &func instead of func to defeat prototype which confuses some tools | ||
| 207 | }, | ||
| 208 | { | ||
| 209 | tags => ['op:intersect'], | ||
| 210 | module => 'Set::Scalar', | ||
| 211 | function => 'intersection', | ||
| 212 | code_template => 'my $s1 = Set::Scalar->new(@{<set1>}); my $s2 = Set::Scalar->new(@{<set2>}); $s1->intersection($s2)', | ||
| 213 | }, | ||
| 214 | # there's no opposite for singleton() yet in List::MoreUtils (as of | ||
| 215 | # v0.413). | ||
| 216 | { | ||
| 217 | tags => ['op:intersect'], | ||
| 218 | fcall_template => 'Array::Set::set_intersect(<set1>, <set2>)', | ||
| 219 | }, | ||
| 220 | { | ||
| 221 | tags => ['op:intersect'], | ||
| 222 | fcall_template => 'Array::Set::Naive::set_intersect(<set1>, <set2>)', | ||
| 223 | }, | ||
| 224 | { | ||
| 225 | tags => ['op:intersect'], | ||
| 226 | module => 'Set::Array', | ||
| 227 | function => 'intersection', | ||
| 228 | code_template => 'my $s1 = Set::Array->new(@{<set1>}); my $s2 = Set::Array->new(@{<set2>}); $s1->intersection($s2)', | ||
| 229 | }, | ||
| 230 | { | ||
| 231 | tags => ['op:intersect'], | ||
| 232 | module => 'Array::AsObject', | ||
| 233 | function => 'intersection', | ||
| 234 | code_template => 'my $s1 = Array::AsObject->new(@{<set1>}); my $s2 = Array::AsObject->new(@{<set2>}); $s1->intersection($s2, 1)', | ||
| 235 | }, | ||
| 236 | { | ||
| 237 | tags => ['op:intersect'], | ||
| 238 | module => 'Set::Object', | ||
| 239 | function => 'intersection', | ||
| 240 | code_template => 'my $s1 = Set::Object->new(@{<set1>}); my $s2 = Set::Object->new(@{<set2>}); $s1->intersection($s2)', | ||
| 241 | }, | ||
| 242 | { | ||
| 243 | tags => ['op:intersect'], | ||
| 244 | module => 'Set::Tiny', | ||
| 245 | function => 'intersection', | ||
| 246 | code_template => 'my $s1 = Set::Tiny->new(@{<set1>}); my $s2 = Set::Tiny->new(@{<set2>}); $s1->intersection($s2)', | ||
| 247 | }, | ||
| 248 | { | ||
| 249 | tags => ['op:intersect'], | ||
| 250 | module => 'List::Collection', | ||
| 251 | function => 'intersect', | ||
| 252 | code_template => '[List::Collection::intersect(<set1>, <set2>)]', | ||
| 253 | }, | ||
| 254 | ], | ||
| 255 | |||
| 256 | # XXX: add more datasets (larger data, etc) | ||
| 257 | datasets => [ | ||
| 258 | { | ||
| 259 | name => 'num10', | ||
| 260 | args => { | ||
| 261 | set1 => [1..10], | ||
| 262 | set2 => [2..11], | ||
| 263 | }, | ||
| 264 | }, | ||
| 265 | { | ||
| 266 | name => 'num100', | ||
| 267 | args => { | ||
| 268 | set1 => [1..100], | ||
| 269 | set2 => [2..101], | ||
| 270 | }, | ||
| 271 | }, | ||
| 272 | { | ||
| 273 | name => 'num1000', | ||
| 274 | args => { | ||
| 275 | set1 => [1..1000], | ||
| 276 | set2 => [2..1001], | ||
| 277 | }, | ||
| 278 | include_by_default => 0, | ||
| 279 | }, | ||
| 280 | ], | ||
| 281 | }; | ||
| 282 | |||
| 283 | 1 | 1; | |
| 284 | # ABSTRACT: Benchmark Perl set operation (union, intersection, diff, symmetric diff) modules | ||
| 285 | |||
| 286 | __END__ | ||