Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use randomly structured Set and Map in benchmarks #1075

Merged
merged 1 commit into from
Dec 14, 2024

Conversation

meooow25
Copy link
Contributor

@meooow25 meooow25 commented Nov 30, 2024

Trees constructed from [1..n] have a specific structure of perfect
binary trees linked together. We shuffle the list so that the tree
is generated from repeated insertions instead, which forms a random
structure that should be more representative of average use cases.

Most benchmarks show an increase in measured times, the amount varying
from 10% to 80%.

@meooow25
Copy link
Contributor Author

This is motivated by #1069 (comment).

@meooow25
Copy link
Contributor Author

meooow25 commented Nov 30, 2024

Effect on benchmarks, GHC 9.10.1:

Set

Expand
Name                           Time - - - - - - - - -    Allocated - - - - - -
                                    A       B       %         A       B       %
alterF:delete                  402 μs  846 μs   +110%    1.9 MB  2.2 MB    +15%
alterF:four                    790 μs  1.1 ms    +39%    2.9 MB  3.1 MB     +4%
alterF:four:strings            1.4 ms  1.8 ms    +22%    3.0 MB  3.0 MB     +0%
alterF:insert                  628 μs  927 μs    +47%    3.6 MB  2.7 MB    -24%
alterF:member                  644 μs  947 μs    +46%    2.4 MB  2.5 MB     +5%
alterF_naive:four              1.1 ms  1.6 ms    +51%    2.0 MB  2.2 MB     +5%
alterF_naive:four:strings      2.8 ms  3.9 ms    +37%    2.1 MB  2.0 MB     -4%
compare                         29 μs   38 μs    +31%    128 KB  128 KB     +0%
delete                         357 μs  771 μs   +115%    1.3 MB  1.6 MB    +19%
deleteMax                       92 ns   97 ns     +5%    511 B   511 B      +0%
deleteMin                       87 ns   85 ns     -2%    471 B   471 B      +0%
difference                      81 μs  180 μs   +123%    239 KB  430 KB    +79%
disjoint:false                  19 ns  700 ns  +3592%     23 B   2.3 KB  +10134%
disjoint:true                  103 μs  121 μs    +17%    218 KB  239 KB     +9%
eq                              29 μs   38 μs    +30%    128 KB  128 KB     +0%
filter                          54 μs   89 μs    +63%     80 KB  119 KB    +49%
findMax                         15 ns   16 ns     +2%     31 B    31 B      +0%
findMin                         14 ns   14 ns     -1%     31 B    31 B      +0%
folds.foldMap_elem             8.0 μs  9.9 μs    +24%      0 B     0 B
folds.foldMap_traverseSum      8.0 μs  8.6 μs     +6%     32 KB   36 KB    +14%
folds.foldl'_sum               8.7 μs   12 μs    +31%      0 B     0 B
folds.foldl_cpsOneShotSum       28 μs   35 μs    +26%    192 KB  192 KB     +0%
folds.foldl_cpsSum              46 μs   54 μs    +17%    287 KB  286 KB     +0%
folds.foldl_skip                19 μs   23 μs    +20%    160 KB  159 KB     +0%
folds.foldl_traverseSum         45 μs   54 μs    +20%    287 KB  286 KB     +0%
folds.foldr'_sum               8.3 μs   12 μs    +39%      0 B     0 B
folds.foldr_cpsOneShotSum       28 μs   34 μs    +25%    192 KB  192 KB     +0%
folds.foldr_cpsSum              44 μs   54 μs    +21%    287 KB  286 KB     +0%
folds.foldr_elem                18 μs   23 μs    +32%    160 KB  159 KB     +0%
folds.foldr_traverseSum         46 μs   54 μs    +16%    287 KB  286 KB     +0%
fromAscList                     48 μs   47 μs     -1%    240 KB  240 KB     +0%
fromDescList                    48 μs   49 μs     +2%    240 KB  240 KB     +0%
fromDistinctAscList             22 μs   21 μs     -3%    223 KB  223 KB     +0%
fromDistinctAscList:fusion      18 μs   18 μs     +1%    288 KB  288 KB     +0%
fromDistinctDescList            21 μs   21 μs     +0%    223 KB  223 KB     +0%
fromDistinctDescList:fusion     18 μs   18 μs     +0%    288 KB  288 KB     +0%
fromList                        48 μs  814 μs  +1584%    271 KB  1.9 MB   +629%
fromList-desc                  453 μs  464 μs     +2%    2.0 MB  2.0 MB     +0%
insert                         554 μs  792 μs    +42%    2.6 MB  1.9 MB    -23%
intersection                    35 μs  176 μs   +407%     80 KB  325 KB   +307%
map                             84 μs   95 μs    +12%    557 KB  557 KB     +0%
member                         139 μs  258 μs    +85%      0 B     0 B
member.powerSet (14)            12 ms   12 ms     +2%     32 MB   32 MB     +0%
member.powerSet (15)            26 ms   27 ms     +3%     73 MB   73 MB     +0%
null.intersection:false         35 μs  180 μs   +414%     80 KB  325 KB   +307%
null.intersection:true          99 μs  115 μs    +16%    298 KB  309 KB     +3%
partition                      111 μs  139 μs    +24%    239 KB  239 KB     +0%
powerSet (15)                  8.1 ms  8.2 ms     +1%    7.5 MB  7.5 MB     +0%
powerSet (16)                   21 ms   21 ms     +0%     15 MB   15 MB     +0%
union                          108 μs  130 μs    +20%    472 KB  484 KB     +2%
unions                         107 μs  130 μs    +21%    472 KB  483 KB     +2%

Map

Expand
Name                                  Time - - - - - - - - -    Allocated - - - - - -
                                           A       B       %         A       B       %
<$                                     25 μs   29 μs    +17%    191 KB  191 KB     +0%
<$ really                              56 μs   67 μs    +20%    191 KB  191 KB     +0%
alter absent                          299 μs  407 μs    +36%    1.0 MB  1.1 MB     +4%
alter delete                          291 μs  469 μs    +61%    1.0 MB  1.1 MB     +8%
alter insert                          296 μs  437 μs    +47%    1.1 MB  1.2 MB     +6%
alter update                          244 μs  346 μs    +41%    985 KB  1.0 MB     +5%
alterF alter absent                   168 μs  238 μs    +42%      0 B     0 B
alterF alter delete                   335 μs  528 μs    +57%    1.3 MB  1.4 MB     +8%
alterF alter insert                   345 μs  487 μs    +41%    1.5 MB  1.6 MB     +6%
alterF alter update                   187 μs  282 μs    +50%    1.3 MB  1.3 MB     +5%
alterF delete absent                  154 μs  231 μs    +49%      0 B     0 B
alterF delete present                 325 μs  525 μs    +61%    1.3 MB  1.4 MB     +9%
alterF insert absent                  349 μs  500 μs    +43%    1.6 MB  1.7 MB     +5%
alterF insert present                 188 μs  277 μs    +47%    1.3 MB  1.4 MB     +5%
alterF lookup absent                   79 μs  131 μs    +65%      0 B     0 B
alterF lookup present                  64 μs  114 μs    +78%     32 KB   32 KB     +0%
alterF no rules alter absent           91 μs  142 μs    +56%      0 B     0 B
alterF no rules alter delete          347 μs  597 μs    +72%    1.0 MB  1.1 MB     +5%
alterF no rules alter insert          373 μs  546 μs    +46%    1.1 MB  1.2 MB     +5%
alterF no rules alter update          229 μs  354 μs    +55%    985 KB  1.0 MB     +4%
alterF no rules delete absent          90 μs  140 μs    +56%      0 B     0 B
alterF no rules delete present        350 μs  570 μs    +62%    1.0 MB  1.1 MB     +6%
alterF no rules insert absent         378 μs  551 μs    +45%    1.2 MB  1.2 MB     +5%
alterF no rules insert present        233 μs  336 μs    +44%    1.0 MB  1.1 MB     +5%
alterF no rules lookup absent          86 μs  142 μs    +64%      0 B     0 B
alterF no rules lookup present         73 μs  131 μs    +79%     32 KB   32 KB     +0%
compare                                40 μs   47 μs    +17%    159 KB  159 KB     +0%
delete absent                         156 μs  219 μs    +40%      0 B     0 B
delete present                        271 μs  448 μs    +65%    1.0 MB  1.1 MB     +8%
difference                             79 μs  183 μs   +132%    287 KB  516 KB    +79%
eq                                     39 μs   46 μs    +16%    159 KB  159 KB     +0%
folds with key.foldMap_elem            10 μs   13 μs    +20%      0 B     0 B
folds with key.foldMap_traverseSum     13 μs   14 μs     +6%     32 KB   36 KB    +13%
folds with key.foldl'_sum              12 μs   15 μs    +26%      0 B     0 B
folds with key.foldl_cpsOneShotSum     42 μs   46 μs     +9%    383 KB  383 KB     +0%
folds with key.foldl_cpsSum            87 μs   81 μs     -7%    607 KB  607 KB     +0%
folds with key.foldl_skip              26 μs   32 μs    +22%    191 KB  191 KB     +0%
folds with key.foldl_traverseSum       76 μs   74 μs     -3%    479 KB  479 KB     +0%
folds with key.foldr'_sum              11 μs   15 μs    +33%      0 B     0 B
folds with key.foldr_cpsOneShotSum     42 μs   46 μs    +10%    383 KB  383 KB     +0%
folds with key.foldr_cpsSum            87 μs   82 μs     -6%    607 KB  607 KB     +0%
folds with key.foldr_elem              26 μs   31 μs    +20%    191 KB  191 KB     +0%
folds with key.foldr_traverseSum       76 μs   74 μs     -2%    479 KB  479 KB     +0%
folds.foldMap_elem                    8.4 μs   12 μs    +46%      0 B     0 B
folds.foldMap_traverseSum              17 μs   20 μs    +17%     64 KB   64 KB     +0%
folds.foldl'_sum                       11 μs   14 μs    +24%      0 B     0 B
folds.foldl_cpsOneShotSum              40 μs   46 μs    +15%    320 KB  319 KB     +0%
folds.foldl_cpsSum                     71 μs   68 μs     -4%    414 KB  414 KB     +0%
folds.foldl_skip                       24 μs   29 μs    +21%    160 KB  160 KB     +0%
folds.foldl_traverseSum                59 μs   59 μs     +0%    287 KB  286 KB     +0%
folds.foldr'_sum                       10 μs   12 μs    +20%      0 B     0 B
folds.foldr_cpsOneShotSum              39 μs   43 μs    +11%    320 KB  319 KB     +0%
folds.foldr_cpsSum                     70 μs   67 μs     -4%    414 KB  414 KB     +0%
folds.foldr_elem                       23 μs   29 μs    +27%    159 KB  159 KB     +0%
folds.foldr_traverseSum                58 μs   60 μs     +2%    287 KB  286 KB     +0%
fromAscList                            51 μs   56 μs     +9%    481 KB  481 KB     +0%
fromAscListWithKey                     59 μs   58 μs     -2%    589 KB  592 KB     +0%
fromDescList                           51 μs   50 μs     +0%    481 KB  481 KB     +0%
fromDescListWithKey                    58 μs   58 μs     +0%    592 KB  589 KB     +0%
fromDistinctAscList                    28 μs   27 μs     -5%    271 KB  272 KB     +0%
fromDistinctAscList:fusion             21 μs   21 μs     +0%    336 KB  336 KB     +0%
fromDistinctDescList                   26 μs   26 μs     +0%    272 KB  272 KB     +0%
fromDistinctDescList:fusion            21 μs   22 μs     +1%    336 KB  336 KB     +0%
fromList                               58 μs  880 μs  +1406%    319 KB  2.3 MB   +649%
fromList-desc                         505 μs  507 μs     +0%    2.6 MB  2.6 MB     +0%
insert absent                         285 μs  429 μs    +50%    1.1 MB  1.2 MB     +6%
insert present                        218 μs  201 μs     -7%    899 KB    0 B    -100%
insertLookupWithKey absent            324 μs  441 μs    +36%    1.1 MB  1.2 MB     +6%
insertLookupWithKey present           260 μs  384 μs    +47%    1.0 MB  1.1 MB     +4%
insertLookupWithKey' absent           296 μs  436 μs    +47%    1.1 MB  1.2 MB     +6%
insertLookupWithKey' present          245 μs  362 μs    +47%    1.0 MB  1.0 MB     +3%
insertWith absent                     284 μs  427 μs    +50%    1.2 MB  1.2 MB     +6%
insertWith present                    229 μs  357 μs    +55%    1.0 MB  1.1 MB     +4%
insertWith' absent                    284 μs  423 μs    +48%    1.2 MB  1.2 MB     +6%
insertWith' present                   225 μs  350 μs    +55%    1.0 MB  1.0 MB     +3%
insertWithKey absent                  286 μs  421 μs    +47%    1.1 MB  1.2 MB     +6%
insertWithKey present                 229 μs  355 μs    +55%    1.0 MB  1.1 MB     +6%
insertWithKey' absent                 291 μs  429 μs    +47%    1.1 MB  1.2 MB     +6%
insertWithKey' present                227 μs  363 μs    +59%    985 KB  1.0 MB     +4%
intersection                           33 μs  192 μs   +485%     96 KB  398 KB   +316%
lookup absent                          80 μs  129 μs    +62%      0 B     0 B
lookup present                         64 μs  122 μs    +90%     32 KB   32 KB     +0%
lookupIndex                           159 μs  161 μs     +1%    128 KB  128 KB     +0%
map                                    31 μs   39 μs    +24%    287 KB  287 KB     +0%
map really                             80 μs   91 μs    +13%    351 KB  351 KB     +0%
mapMaybe                               90 μs  105 μs    +17%    247 KB  250 KB     +1%
mapMaybeWithKey                        90 μs  106 μs    +17%    247 KB  250 KB     +1%
mapWithKey                             37 μs   42 μs    +15%    352 KB  352 KB     +0%
minView                                23 ns   22 ns     -5%    135 B   135 B      +0%
split                                 8.5 ns  194 ns  +2194%     47 B   1.1 KB  +2236%
union                                 112 μs  134 μs    +20%    561 KB  579 KB     +3%
update absent                         272 μs  393 μs    +44%    1.0 MB  1.1 MB     +4%
update delete                         269 μs  455 μs    +69%    1.0 MB  1.1 MB     +8%
update present                        211 μs  321 μs    +52%    861 KB  905 KB     +5%
updateLookupWithKey absent            297 μs  404 μs    +36%    1.0 MB  1.1 MB     +4%
updateLookupWithKey delete            283 μs  470 μs    +66%    1.0 MB  1.1 MB     +6%
updateLookupWithKey present           234 μs  334 μs    +42%    893 KB  936 KB     +4%

Set operations, Set

Expand
Name                                  Time - - - - - - - - -    Allocated - - - - - -
                                           A       B       %         A       B       %
difference-block_nn                   386 μs  460 μs    +19%    1.0 MB  1.1 MB     +8%
difference-block_nn_swap              394 μs  457 μs    +15%    1.0 MB  1.1 MB     +4%
difference-block_ns                    47 μs   52 μs    +10%    143 KB  151 KB     +5%
difference-block_sn_swap               47 μs   51 μs     +8%    135 KB  141 KB     +4%
difference-common_nn                  3.1 ms  6.8 ms   +117%    5.6 MB   10 MB    +82%
difference-common_nn_swap             566 μs  3.3 ms   +490%      0 B   5.0 MB
difference-common_ns                  2.2 ms  3.2 ms    +46%    4.7 MB  5.0 MB     +7%
difference-common_nt                  124 μs  145 μs    +16%    334 KB  356 KB     +6%
difference-common_sn_swap             879 μs  1.2 ms    +34%    1.8 MB  1.9 MB     +5%
difference-common_tn_swap              75 μs   80 μs     +7%    123 KB  129 KB     +5%
difference-disj_nn                    3.1 μs  2.8 μs     -9%     11 KB   10 KB     -9%
difference-disj_nn_swap               2.7 μs  2.6 μs     -4%     11 KB   10 KB     -5%
difference-disj_ns                    2.4 μs  2.3 μs     -2%    8.3 KB  8.1 KB     -2%
difference-disj_nt                    1.5 μs  1.4 μs     -3%    5.1 KB  5.0 KB     -3%
difference-disj_sn_swap               2.2 μs  2.4 μs    +10%    8.1 KB  8.5 KB     +4%
difference-disj_tn_swap               1.4 μs  1.5 μs     +1%    5.0 KB  5.0 KB     +0%
difference-mix_nn                     6.0 ms  6.6 ms     +9%     14 MB   15 MB     +5%
difference-mix_nn_swap                5.9 ms  6.4 ms     +9%     14 MB   15 MB     +5%
difference-mix_ns                     1.3 ms  1.9 ms    +48%    3.8 MB  4.0 MB     +6%
difference-mix_nt                      88 μs  111 μs    +25%    239 KB  258 KB     +8%
difference-mix_sn_swap                1.3 ms  1.6 ms    +27%    2.7 MB  2.7 MB     +2%
difference-mix_tn_swap                 84 μs   95 μs    +12%    147 KB  151 KB     +3%
intersection-block_nn                 388 μs  463 μs    +19%    1.0 MB  1.1 MB     +4%
intersection-block_nn_swap            383 μs  465 μs    +21%    1.0 MB  1.1 MB     +8%
intersection-block_ns                  47 μs   52 μs    +10%    135 KB  141 KB     +4%
intersection-block_sn_swap             47 μs   52 μs     +9%    143 KB  151 KB     +5%
intersection-common_nn                1.1 ms  6.1 ms   +459%    1.9 MB  7.7 MB   +305%
intersection-common_nn_swap           534 μs  2.8 ms   +427%      0 B   4.7 MB
intersection-common_ns                1.3 ms  1.7 ms    +28%    2.5 MB  2.7 MB     +5%
intersection-common_nt                 95 μs  102 μs     +7%    151 KB  159 KB     +5%
intersection-common_sn_swap           898 μs  1.4 ms    +56%    2.7 MB  3.0 MB    +10%
intersection-common_tn_swap            83 μs   98 μs    +18%    210 KB  231 KB     +9%
intersection-disj_nn                  2.8 μs  2.7 μs     -5%     11 KB   10 KB     -5%
intersection-disj_nn_swap             3.1 μs  2.9 μs     -7%     11 KB   10 KB     -9%
intersection-disj_ns                  2.2 μs  2.4 μs    +10%    8.1 KB  8.5 KB     +4%
intersection-disj_nt                  1.5 μs  1.5 μs     +1%    5.0 KB  5.0 KB     +0%
intersection-disj_sn_swap             2.4 μs  2.3 μs     -2%    8.3 KB  8.1 KB     -2%
intersection-disj_tn_swap             1.5 μs  1.4 μs     -2%    5.1 KB  5.0 KB     -3%
intersection-mix_nn                   5.4 ms  6.1 ms    +14%     14 MB   15 MB     +5%
intersection-mix_nn_swap              5.4 ms  6.0 ms    +11%     14 MB   15 MB     +5%
intersection-mix_ns                   1.3 ms  1.6 ms    +24%    2.7 MB  2.7 MB     +2%
intersection-mix_nt                    87 μs   98 μs    +12%    147 KB  151 KB     +3%
intersection-mix_sn_swap              1.2 ms  1.8 ms    +53%    3.8 MB  4.0 MB     +6%
intersection-mix_tn_swap               91 μs  111 μs    +21%    234 KB  258 KB    +10%
symmetricDifference-block_nn          581 μs  682 μs    +17%    1.6 MB  1.7 MB     +3%
symmetricDifference-block_nn_swap     579 μs  678 μs    +17%    1.6 MB  1.7 MB     +3%
symmetricDifference-block_ns           64 μs   70 μs     +9%    202 KB  210 KB     +3%
symmetricDifference-block_sn_swap      71 μs   78 μs     +9%    234 KB  247 KB     +5%
symmetricDifference-common_nn         2.4 ms  6.1 ms   +155%    3.7 MB  7.7 MB   +105%
symmetricDifference-common_nn_swap    2.3 ms  6.5 ms   +178%    3.7 MB  8.5 MB   +126%
symmetricDifference-common_ns         1.5 ms  2.1 ms    +34%    3.1 MB  3.2 MB     +3%
symmetricDifference-common_nt         107 μs  117 μs     +9%    231 KB  239 KB     +3%
symmetricDifference-common_sn_swap    2.0 ms  3.1 ms    +50%    4.3 MB  4.6 MB     +6%
symmetricDifference-common_tn_swap    120 μs  147 μs    +22%    325 KB  341 KB     +4%
symmetricDifference-disj_nn           4.4 μs  4.0 μs     -9%     18 KB   16 KB    -11%
symmetricDifference-disj_nn_swap      4.5 μs  4.3 μs     -4%     18 KB   16 KB     -8%
symmetricDifference-disj_ns           3.3 μs  3.3 μs     +0%     13 KB   12 KB     -5%
symmetricDifference-disj_nt           2.0 μs  1.9 μs     -7%    7.9 KB  7.1 KB    -10%
symmetricDifference-disj_sn_swap      3.7 μs  3.7 μs     +1%     14 KB   15 KB     +2%
symmetricDifference-disj_tn_swap      2.4 μs  2.4 μs     +0%    9.8 KB  9.5 KB     -2%
symmetricDifference-mix_nn             16 ms   18 ms    +13%     18 MB   19 MB     +3%
symmetricDifference-mix_nn_swap        16 ms   18 ms    +12%     18 MB   19 MB     +3%
symmetricDifference-mix_ns            2.4 ms  3.2 ms    +36%    4.6 MB  5.1 MB    +10%
symmetricDifference-mix_nt            111 μs  127 μs    +14%    271 KB  293 KB     +8%
symmetricDifference-mix_sn_swap       2.1 ms  3.1 ms    +46%    4.1 MB  4.5 MB     +9%
symmetricDifference-mix_tn_swap        95 μs  118 μs    +24%    250 KB  270 KB     +8%
union-block_nn                        557 μs  653 μs    +17%    1.6 MB  1.6 MB     +4%
union-block_nn_swap                   544 μs  659 μs    +21%    1.6 MB  1.6 MB     +3%
union-block_ns                         60 μs   68 μs    +12%    195 KB  203 KB     +4%
union-block_sn_swap                    66 μs   74 μs    +12%    223 KB  237 KB     +6%
union-common_nn                       379 μs  2.9 ms   +671%      0 B   4.7 MB
union-common_nn_swap                  956 μs  7.4 ms   +678%    2.3 MB  7.2 MB   +218%
union-common_ns                       586 μs  862 μs    +46%    1.2 MB  1.3 MB     +5%
union-common_nt                        38 μs   40 μs     +5%     45 KB   49 KB     +6%
union-common_sn_swap                  1.3 ms  1.7 ms    +26%    2.9 MB  2.8 MB     -4%
union-common_tn_swap                   76 μs   86 μs    +13%    191 KB  199 KB     +4%
union-disj_nn                         4.2 μs  3.8 μs     -9%     17 KB   16 KB     -9%
union-disj_nn_swap                    4.4 μs  4.0 μs     -7%     17 KB   16 KB     -6%
union-disj_ns                         3.2 μs  3.2 μs     +0%     13 KB   12 KB     -5%
union-disj_nt                         2.0 μs  1.9 μs     -6%    7.5 KB  6.8 KB     -9%
union-disj_sn_swap                    3.6 μs  3.5 μs     +0%     14 KB   14 KB     +1%
union-disj_tn_swap                    2.3 μs  2.2 μs     -2%    9.1 KB  9.0 KB     -1%
union-mix_nn                           17 ms   20 ms    +18%     23 MB   23 MB     +2%
union-mix_nn_swap                      17 ms   20 ms    +19%     23 MB   23 MB     +2%
union-mix_ns                          1.5 ms  2.1 ms    +42%    3.4 MB  3.8 MB    +10%
union-mix_nt                           73 μs   83 μs    +13%    170 KB  186 KB     +9%
union-mix_sn_swap                     1.7 ms  3.4 ms   +102%    3.7 MB  4.0 MB     +7%
union-mix_tn_swap                      79 μs   99 μs    +24%    207 KB  226 KB     +9%

Set operations, Map

Expand
Name                                  Time - - - - - - - - -    Allocated - - - - - -
                                           A       B       %         A       B       %
difference-block_nn                   373 μs  423 μs    +13%    1.2 MB  1.3 MB     +6%
difference-block_nn_swap              380 μs  423 μs    +11%    1.2 MB  1.3 MB     +5%
difference-block_ns                    44 μs   49 μs    +10%    171 KB  183 KB     +6%
difference-block_sn_swap               45 μs   49 μs     +8%    163 KB  169 KB     +3%
difference-common_nn                  3.8 ms  7.6 ms    +99%    6.8 MB   12 MB    +82%
difference-common_nn_swap             480 μs  3.4 ms   +613%      0 B   6.0 MB
difference-common_ns                  3.2 ms  4.1 ms    +27%    5.6 MB  6.0 MB     +5%
difference-common_nt                  125 μs  145 μs    +16%    406 KB  430 KB     +5%
difference-common_sn_swap             817 μs  1.1 ms    +38%    2.1 MB  2.2 MB     +5%
difference-common_tn_swap              70 μs   75 μs     +7%    147 KB  155 KB     +5%
difference-disj_nn                    2.9 μs  2.6 μs    -10%     13 KB   12 KB     -9%
difference-disj_nn_swap               2.4 μs  2.4 μs     -3%     13 KB   12 KB     -5%
difference-disj_ns                    2.2 μs  2.1 μs     -4%     10 KB  9.7 KB     -2%
difference-disj_nt                    1.3 μs  1.3 μs     -4%    6.2 KB  6.0 KB     -3%
difference-disj_sn_swap               2.0 μs  2.1 μs     +8%    9.7 KB   10 KB     +3%
difference-disj_tn_swap               1.3 μs  1.3 μs     +1%    6.0 KB  6.0 KB     +0%
difference-mix_nn                     7.0 ms  6.9 ms     +0%     17 MB   18 MB     +5%
difference-mix_nn_swap                6.8 ms  6.9 ms     +0%     17 MB   18 MB     +5%
difference-mix_ns                     1.2 ms  1.9 ms    +57%    4.6 MB  4.9 MB     +7%
difference-mix_nt                      89 μs  112 μs    +24%    286 KB  310 KB     +8%
difference-mix_sn_swap                1.2 ms  1.6 ms    +35%    3.2 MB  3.3 MB     +1%
difference-mix_tn_swap                 78 μs   88 μs    +12%    175 KB  183 KB     +4%
intersection-block_nn                 380 μs  440 μs    +15%    1.2 MB  1.3 MB     +5%
intersection-block_nn_swap            378 μs  442 μs    +17%    1.2 MB  1.3 MB     +6%
intersection-block_ns                  46 μs   51 μs     +9%    163 KB  169 KB     +3%
intersection-block_sn_swap             46 μs   50 μs     +8%    171 KB  183 KB     +6%
intersection-common_nn                1.2 ms  6.8 ms   +463%    2.3 MB  9.2 MB   +304%
intersection-common_nn_swap           468 μs  2.9 ms   +529%      0 B   5.6 MB
intersection-common_ns                1.3 ms  1.7 ms    +30%    3.0 MB  3.2 MB     +4%
intersection-common_nt                 89 μs   97 μs     +8%    183 KB  191 KB     +4%
intersection-common_sn_swap           938 μs  1.4 ms    +50%    3.2 MB  3.5 MB     +9%
intersection-common_tn_swap            81 μs   95 μs    +17%    255 KB  274 KB     +7%
intersection-disj_nn                  2.5 μs  2.3 μs     -6%     13 KB   12 KB     -5%
intersection-disj_nn_swap             2.9 μs  2.5 μs    -13%     13 KB   12 KB     -9%
intersection-disj_ns                  2.0 μs  2.1 μs     +6%    9.7 KB   10 KB     +3%
intersection-disj_nt                  1.4 μs  1.4 μs     -1%    6.0 KB  6.0 KB     +0%
intersection-disj_sn_swap             2.2 μs  2.0 μs     -7%     10 KB  9.7 KB     -3%
intersection-disj_tn_swap             1.4 μs  1.3 μs     -6%    6.2 KB  6.0 KB     -3%
intersection-mix_nn                   5.8 ms  6.5 ms    +12%     17 MB   18 MB     +5%
intersection-mix_nn_swap              6.0 ms  6.4 ms     +7%     17 MB   18 MB     +5%
intersection-mix_ns                   1.2 ms  1.7 ms    +36%    3.2 MB  3.3 MB     +1%
intersection-mix_nt                    83 μs   95 μs    +14%    177 KB  183 KB     +3%
intersection-mix_sn_swap              1.2 ms  2.0 ms    +58%    4.6 MB  4.9 MB     +7%
intersection-mix_tn_swap               90 μs  113 μs    +25%    282 KB  310 KB    +10%
symmetricDifference-block_nn          558 μs  707 μs    +26%    2.0 MB  2.1 MB     +4%
symmetricDifference-block_nn_swap     558 μs  695 μs    +24%    2.0 MB  2.1 MB     +5%
symmetricDifference-block_ns           63 μs   68 μs     +8%    242 KB  250 KB     +3%
symmetricDifference-block_sn_swap      70 μs   76 μs     +8%    282 KB  298 KB     +5%
symmetricDifference-common_nn         2.8 ms  6.8 ms   +139%    4.5 MB  9.5 MB   +110%
symmetricDifference-common_nn_swap    2.7 ms  6.8 ms   +149%    4.5 MB   10 MB   +122%
symmetricDifference-common_ns         1.6 ms  2.2 ms    +37%    3.8 MB  4.0 MB     +6%
symmetricDifference-common_nt         104 μs  115 μs    +10%    274 KB  290 KB     +5%
symmetricDifference-common_sn_swap    2.6 ms  3.7 ms    +42%    5.1 MB  5.6 MB     +8%
symmetricDifference-common_tn_swap    123 μs  149 μs    +20%    388 KB  417 KB     +7%
symmetricDifference-disj_nn           4.2 μs  3.8 μs    -10%     22 KB   19 KB    -11%
symmetricDifference-disj_nn_swap      4.4 μs  4.1 μs     -7%     21 KB   20 KB     -6%
symmetricDifference-disj_ns           3.1 μs  3.1 μs     -1%     16 KB   15 KB     -5%
symmetricDifference-disj_nt           2.0 μs  1.8 μs    -10%    9.4 KB  8.5 KB    -10%
symmetricDifference-disj_sn_swap      3.5 μs  3.5 μs     +0%     17 KB   18 KB     +2%
symmetricDifference-disj_tn_swap      2.4 μs  2.3 μs     -3%     12 KB   11 KB     -2%
symmetricDifference-mix_nn             18 ms   20 ms     +8%     22 MB   23 MB     +3%
symmetricDifference-mix_nn_swap        18 ms   20 ms     +7%     22 MB   22 MB     +3%
symmetricDifference-mix_ns            2.9 ms  3.9 ms    +34%    5.6 MB  6.1 MB     +8%
symmetricDifference-mix_nt            111 μs  125 μs    +12%    327 KB  354 KB     +8%
symmetricDifference-mix_sn_swap       2.9 ms  4.0 ms    +37%    5.0 MB  5.3 MB     +6%
symmetricDifference-mix_tn_swap        96 μs  121 μs    +26%    298 KB  326 KB     +9%
union-block_nn                        568 μs  662 μs    +16%    1.9 MB  2.0 MB     +4%
union-block_nn_swap                   567 μs  656 μs    +15%    1.9 MB  2.0 MB     +4%
union-block_ns                         59 μs   67 μs    +12%    234 KB  242 KB     +3%
union-block_sn_swap                    67 μs   73 μs     +9%    266 KB  282 KB     +5%
union-common_nn                       353 μs  3.2 ms   +799%      0 B   5.6 MB
union-common_nn_swap                  1.1 ms  7.8 ms   +630%    2.3 MB  8.2 MB   +256%
union-common_ns                       591 μs  900 μs    +52%    1.5 MB  1.5 MB     +4%
union-common_nt                        39 μs   42 μs     +6%     56 KB   57 KB     +2%
union-common_sn_swap                  1.4 ms  1.8 ms    +28%    3.5 MB  3.4 MB     -3%
union-common_tn_swap                   77 μs   83 μs     +8%    231 KB  238 KB     +3%
union-disj_nn                         4.1 μs  3.7 μs    -11%     21 KB   19 KB     -9%
union-disj_nn_swap                    4.2 μs  4.0 μs     -4%     21 KB   19 KB     -7%
union-disj_ns                         3.1 μs  3.0 μs     -1%     15 KB   14 KB     -5%
union-disj_nt                         1.9 μs  1.8 μs     -9%    9.1 KB  8.1 KB    -10%
union-disj_sn_swap                    3.4 μs  3.4 μs     +2%     17 KB   17 KB     +2%
union-disj_tn_swap                    2.2 μs  2.2 μs     +0%     11 KB   11 KB     -2%
union-mix_nn                           20 ms   22 ms    +12%     27 MB   28 MB     +2%
union-mix_nn_swap                      20 ms   23 ms    +11%     27 MB   28 MB     +2%
union-mix_ns                          1.8 ms  2.7 ms    +51%    4.1 MB  4.5 MB     +9%
union-mix_nt                           74 μs   83 μs    +12%    207 KB  223 KB     +7%
union-mix_sn_swap                     2.4 ms  3.3 ms    +37%    4.4 MB  4.7 MB     +6%
union-mix_tn_swap                      82 μs   98 μs    +19%    247 KB  270 KB     +9%

Edit: I had repeated the Map benchmarks under Set, fixed now.
Edit 2: Added set operations benchmarks

@meooow25 meooow25 force-pushed the random-set-map-bench branch 2 times, most recently from 56f8df1 to 032ab37 Compare November 30, 2024 16:29
@HuwCampbell
Copy link

👍

The large change for fromList is expected, split must have been hitting the perfect balance root straight off as well and not performing any rebalancing. I imagine intersection was similarly finding the items right at the roots.

@meooow25 meooow25 force-pushed the random-set-map-bench branch from 032ab37 to bb1b662 Compare December 10, 2024 15:06
@meooow25
Copy link
Contributor Author

That's correct. To explain the large increases a little more,

  • fromList goes from O(n) to O(n log n), so the increase is expected.
  • split (bound `div` 2) (fromList [1..bound]) for bound = 2^12 hits the split value at the root, so it was fast. This is no longer the case.
  • Set operations like intersection use split/splitMember internally, which found values at the root for certain tidy inputs. This is no longer the case.

Overall I don't see anything unusual, the changes in the numbers are reasonable.

Trees constructed from [1..n] have a specific structure of perfect
binary trees linked together. We shuffle the list so that the tree
is generated from repeated insertions instead, which forms a random
structure that should be more representative of average use cases.

Most benchmarks show an increase in measured times, the amount varying
from 10% to 70%. This is expected because the trees are more unbalanced
now. A handful of benchmarks show larger increases. These were previously
measuring best-case scenarios, which no longer occurs with random trees.
@meooow25 meooow25 force-pushed the random-set-map-bench branch from bb1b662 to ea138a9 Compare December 10, 2024 15:49
@meooow25 meooow25 merged commit b0b2cb5 into haskell:master Dec 14, 2024
12 checks passed
@meooow25 meooow25 deleted the random-set-map-bench branch December 14, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants