Skip to content

[libc++][format][2/7] Optimizes c-string arguments. #101805

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

Merged

Conversation

mordante
Copy link
Member

@mordante mordante commented Aug 3, 2024

The formatter specializations for _CharT* and const _CharT* typically write all elements in a loop. This format's internal functions are optimized for larger writes.

Instead of writing one element at a time, convert the range to a basic_string_view and write that instead.

For C string of 6 characters this is a bit slower, but for 60 characters it's faster. The improvements for back_inserter<std::list<_CharT>> are not as great as the others; it just gets as slow as basic_string_view<_CharT>.

Before
---------------------------------------------------------------------------------------------------------------
Benchmark                                                                     Time             CPU   Iterations
---------------------------------------------------------------------------------------------------------------
BM_sprintf/C string len = 6                                                4.81 ns         4.80 ns    145890280
BM_format/C string len = 6                                                 52.6 ns         52.4 ns     13252327
BM_format_to_back_inserter<std::string>/C string len = 6                   53.0 ns         52.8 ns     13262680
BM_format_to_back_inserter<std::vector<char>>/C string len = 6             69.7 ns         69.6 ns     10045636
BM_format_to_back_inserter<std::deque<char>>/C string len = 6               148 ns          148 ns      4729368
BM_format_to_back_inserter<std::list<char>>/C string len = 6                127 ns          126 ns      5538441
BM_format_to_iterator/<std::array> C string len = 6                        42.9 ns         42.8 ns     16367158
BM_format_to_iterator/<std::string> C string len = 6                       43.5 ns         43.4 ns     16141644
BM_format_to_iterator/<std::vector> C string len = 6                       42.9 ns         42.8 ns     16366718
BM_format_to_iterator/<std::deque> C string len = 6                        47.8 ns         47.7 ns     14686488
BM_format/string len = 6                                                   55.3 ns         55.2 ns     12696889
BM_format_to_back_inserter<std::string>/string len = 6                     55.4 ns         55.2 ns     12660731
BM_format_to_back_inserter<std::vector<char>>/string len = 6               70.7 ns         70.5 ns      9927313
BM_format_to_back_inserter<std::deque<char>>/string len = 6                 153 ns          153 ns      4573936
BM_format_to_back_inserter<std::list<char>>/string len = 6                  128 ns          128 ns      5486033
BM_format_to_iterator/<std::array> string len = 6                          44.6 ns         44.5 ns     15758122
BM_format_to_iterator/<std::string> string len = 6                         44.7 ns         44.6 ns     15690226
BM_format_to_iterator/<std::vector> string len = 6                         44.3 ns         44.2 ns     15715898
BM_format_to_iterator/<std::deque> string len = 6                          50.3 ns         50.1 ns     13958635
BM_format/string_view len = 6                                              54.2 ns         54.1 ns     12929525
BM_format_to_back_inserter<std::string>/string_view len = 6                54.3 ns         54.1 ns     12929219
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6          70.0 ns         69.8 ns     10022355
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6            153 ns          152 ns      4585749
BM_format_to_back_inserter<std::list<char>>/string_view len = 6             128 ns          128 ns      5489760
BM_format_to_iterator/<std::array> string_view len = 6                     44.2 ns         44.1 ns     15884839
BM_format_to_iterator/<std::string> string_view len = 6                    44.8 ns         44.6 ns     15664278
BM_format_to_iterator/<std::vector> string_view len = 6                    44.7 ns         44.6 ns     15716983
BM_format_to_iterator/<std::deque> string_view len = 6                     50.3 ns         50.2 ns     13936091
BM_sprintf/C string len = 60                                               4.16 ns         4.15 ns    168764227
BM_format/C string len = 60                                                 169 ns          169 ns      4144060
BM_format_to_back_inserter<std::string>/C string len = 60                   167 ns          167 ns      4203915
BM_format_to_back_inserter<std::vector<char>>/C string len = 60             177 ns          176 ns      3965619
BM_format_to_back_inserter<std::deque<char>>/C string len = 60              383 ns          382 ns      1832531
BM_format_to_back_inserter<std::list<char>>/C string len = 60              1270 ns         1267 ns       552686
BM_format_to_iterator/<std::array> C string len = 60                        141 ns          140 ns      4988441
BM_format_to_iterator/<std::string> C string len = 60                       141 ns          141 ns      4956101
BM_format_to_iterator/<std::vector> C string len = 60                       141 ns          141 ns      4963443
BM_format_to_iterator/<std::deque> C string len = 60                        144 ns          143 ns      4893139
BM_format/string len = 60                                                  73.4 ns         73.2 ns      9548455
BM_format_to_back_inserter<std::string>/string len = 60                    73.2 ns         73.0 ns      9524524
BM_format_to_back_inserter<std::vector<char>>/string len = 60              81.6 ns         81.4 ns      8584033
BM_format_to_back_inserter<std::deque<char>>/string len = 60                279 ns          279 ns      2515146
BM_format_to_back_inserter<std::list<char>>/string len = 60                1177 ns         1174 ns       597172
BM_format_to_iterator/<std::array> string len = 60                         44.5 ns         44.4 ns     15753131
BM_format_to_iterator/<std::string> string len = 60                        44.7 ns         44.6 ns     15692630
BM_format_to_iterator/<std::vector> string len = 60                        44.8 ns         44.7 ns     15664689
BM_format_to_iterator/<std::deque> string len = 60                         50.6 ns         50.5 ns     13838617
BM_format/string_view len = 60                                             72.8 ns         72.6 ns      9674007
BM_format_to_back_inserter<std::string>/string_view len = 60               72.7 ns         72.6 ns      9638209
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60         82.6 ns         82.4 ns      8496602
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60           280 ns          280 ns      2508982
BM_format_to_back_inserter<std::list<char>>/string_view len = 60           1176 ns         1173 ns       597714
BM_format_to_iterator/<std::array> string_view len = 60                    44.2 ns         44.1 ns     15896934
BM_format_to_iterator/<std::string> string_view len = 60                   44.7 ns         44.6 ns     15695427
BM_format_to_iterator/<std::vector> string_view len = 60                   44.7 ns         44.6 ns     15680899
BM_format_to_iterator/<std::deque> string_view len = 60                    50.3 ns         50.1 ns     13962755
BM_sprintf/C string len = 6000                                              114 ns          114 ns      6170153
BM_format/C string len = 6000                                             11792 ns        11763 ns        59619
BM_format_to_back_inserter<std::string>/C string len = 6000               11778 ns        11746 ns        59572
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000         11715 ns        11686 ns        60053
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000          25464 ns        25403 ns        27538
BM_format_to_back_inserter<std::list<char>>/C string len = 6000          126044 ns       125726 ns         5572
BM_format_to_iterator/<std::array> C string len = 6000                    10792 ns        10766 ns        64943
BM_format_to_iterator/<std::string> C string len = 6000                   10791 ns        10761 ns        64918
BM_format_to_iterator/<std::vector> C string len = 6000                   10775 ns        10750 ns        65149
BM_format_to_iterator/<std::deque> C string len = 6000                    11242 ns        11215 ns        62542
BM_format/string len = 6000                                                 919 ns          917 ns       763961
BM_format_to_back_inserter<std::string>/string len = 6000                   920 ns          917 ns       763094
BM_format_to_back_inserter<std::vector<char>>/string len = 6000             888 ns          886 ns       793468
BM_format_to_back_inserter<std::deque<char>>/string len = 6000            14999 ns        14963 ns        46758
BM_format_to_back_inserter<std::list<char>>/string len = 6000            114504 ns       114213 ns         6130
BM_format_to_iterator/<std::array> string len = 6000                        120 ns          120 ns      5823426
BM_format_to_iterator/<std::string> string len = 6000                       106 ns          106 ns      6609299
BM_format_to_iterator/<std::vector> string len = 6000                       106 ns          106 ns      6613867
BM_format_to_iterator/<std::deque> string len = 6000                        367 ns          366 ns      1912818
BM_format/string_view len = 6000                                            910 ns          907 ns       771491
BM_format_to_back_inserter<std::string>/string_view len = 6000              911 ns          909 ns       770065
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000        878 ns          876 ns       794976
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000       15031 ns        14994 ns        46651
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000       114510 ns       114219 ns         6130
BM_format_to_iterator/<std::array> string_view len = 6000                   121 ns          120 ns      5814249
BM_format_to_iterator/<std::string> string_view len = 6000                  116 ns          115 ns      6072315
BM_format_to_iterator/<std::vector> string_view len = 6000                  115 ns          115 ns      6095762
BM_format_to_iterator/<std::deque> string_view len = 6000                   351 ns          350 ns      2002175

After
---------------------------------------------------------------------------------------------------------------
Benchmark                                                                     Time             CPU   Iterations
---------------------------------------------------------------------------------------------------------------
BM_sprintf/C string len = 6                                                4.83 ns         4.83 ns    145502957
BM_format/C string len = 6                                                 55.1 ns         55.1 ns     12687656
BM_format_to_back_inserter<std::string>/C string len = 6                   55.1 ns         55.1 ns     12691642
BM_format_to_back_inserter<std::vector<char>>/C string len = 6             71.2 ns         71.3 ns      9819560
BM_format_to_back_inserter<std::deque<char>>/C string len = 6               154 ns          154 ns      4548709
BM_format_to_back_inserter<std::list<char>>/C string len = 6                131 ns          131 ns      5338318
BM_format_to_iterator/<std::array> C string len = 6                        45.0 ns         45.0 ns     15569429
BM_format_to_iterator/<std::string> C string len = 6                       45.9 ns         45.9 ns     15240594
BM_format_to_iterator/<std::vector> C string len = 6                       44.4 ns         44.4 ns     15768343
BM_format_to_iterator/<std::deque> C string len = 6                        50.1 ns         50.1 ns     13995837
BM_format/string len = 6                                                   54.8 ns         54.8 ns     12738209
BM_format_to_back_inserter<std::string>/string len = 6                     55.4 ns         55.4 ns     12634483
BM_format_to_back_inserter<std::vector<char>>/string len = 6               70.4 ns         70.4 ns      9948288
BM_format_to_back_inserter<std::deque<char>>/string len = 6                 154 ns          154 ns      4531741
BM_format_to_back_inserter<std::list<char>>/string len = 6                  132 ns          132 ns      5289798
BM_format_to_iterator/<std::array> string len = 6                          44.5 ns         44.5 ns     15743437
BM_format_to_iterator/<std::string> string len = 6                         44.9 ns         44.9 ns     15591961
BM_format_to_iterator/<std::vector> string len = 6                         45.0 ns         45.0 ns     15541308
BM_format_to_iterator/<std::deque> string len = 6                          50.5 ns         50.5 ns     13837884
BM_format/string_view len = 6                                              54.5 ns         54.5 ns     12833591
BM_format_to_back_inserter<std::string>/string_view len = 6                54.6 ns         54.6 ns     12818233
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6          69.9 ns         69.9 ns     10018025
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6            154 ns          154 ns      4534215
BM_format_to_back_inserter<std::list<char>>/string_view len = 6             131 ns          131 ns      5337938
BM_format_to_iterator/<std::array> string_view len = 6                     44.2 ns         44.2 ns     15854695
BM_format_to_iterator/<std::string> string_view len = 6                    45.0 ns         45.0 ns     15551054
BM_format_to_iterator/<std::vector> string_view len = 6                    45.0 ns         45.0 ns     15567905
BM_format_to_iterator/<std::deque> string_view len = 6                     50.5 ns         50.5 ns     13858261
BM_sprintf/C string len = 60                                               4.16 ns         4.16 ns    168066307
BM_format/C string len = 60                                                73.8 ns         73.8 ns      9487364
BM_format_to_back_inserter<std::string>/C string len = 60                  73.7 ns         73.7 ns      9492371
BM_format_to_back_inserter<std::vector<char>>/C string len = 60            83.1 ns         83.1 ns      8399017
BM_format_to_back_inserter<std::deque<char>>/C string len = 60              284 ns          284 ns      2466510
BM_format_to_back_inserter<std::list<char>>/C string len = 60              1177 ns         1177 ns       592514
BM_format_to_iterator/<std::array> C string len = 60                       44.9 ns         44.9 ns     15558172
BM_format_to_iterator/<std::string> C string len = 60                      45.8 ns         45.8 ns     15283103
BM_format_to_iterator/<std::vector> C string len = 60                      44.6 ns         44.6 ns     15678967
BM_format_to_iterator/<std::deque> C string len = 60                       50.5 ns         50.5 ns     13839524
BM_format/string len = 60                                                  72.2 ns         72.2 ns      9687634
BM_format_to_back_inserter<std::string>/string len = 60                    72.0 ns         72.1 ns      9695746
BM_format_to_back_inserter<std::vector<char>>/string len = 60              82.3 ns         82.3 ns      8509528
BM_format_to_back_inserter<std::deque<char>>/string len = 60                279 ns          279 ns      2506108
BM_format_to_back_inserter<std::list<char>>/string len = 60                1180 ns         1180 ns       592963
BM_format_to_iterator/<std::array> string len = 60                         44.7 ns         44.7 ns     15657865
BM_format_to_iterator/<std::string> string len = 60                        45.0 ns         45.0 ns     15569049
BM_format_to_iterator/<std::vector> string len = 60                        44.9 ns         44.9 ns     15576187
BM_format_to_iterator/<std::deque> string len = 60                         50.7 ns         50.7 ns     13803188
BM_format/string_view len = 60                                             72.4 ns         72.4 ns      9663061
BM_format_to_back_inserter<std::string>/string_view len = 60               72.8 ns         72.8 ns      9638941
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60         81.9 ns         81.9 ns      8529931
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60           283 ns          283 ns      2471522
BM_format_to_back_inserter<std::list<char>>/string_view len = 60           1177 ns         1177 ns       594752
BM_format_to_iterator/<std::array> string_view len = 60                    44.2 ns         44.2 ns     15841413
BM_format_to_iterator/<std::string> string_view len = 60                   45.1 ns         45.1 ns     15546279
BM_format_to_iterator/<std::vector> string_view len = 60                   45.0 ns         45.0 ns     15555756
BM_format_to_iterator/<std::deque> string_view len = 60                    50.1 ns         50.1 ns     10000000
BM_sprintf/C string len = 6000                                              344 ns          344 ns      2037753
BM_format/C string len = 6000                                               980 ns          980 ns       713341
BM_format_to_back_inserter<std::string>/C string len = 6000                 979 ns          979 ns       709571
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000           944 ns          944 ns       744518
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000          14916 ns        14915 ns        46875
BM_format_to_back_inserter<std::list<char>>/C string len = 6000          114686 ns       114688 ns         6110
BM_format_to_iterator/<std::array> C string len = 6000                      159 ns          159 ns      4394506
BM_format_to_iterator/<std::string> C string len = 6000                     159 ns          159 ns      4384577
BM_format_to_iterator/<std::vector> C string len = 6000                     159 ns          159 ns      4393225
BM_format_to_iterator/<std::deque> C string len = 6000                      437 ns          437 ns      1601253
BM_format/string len = 6000                                                 929 ns          929 ns       751889
BM_format_to_back_inserter<std::string>/string len = 6000                   933 ns          933 ns       752042
BM_format_to_back_inserter<std::vector<char>>/string len = 6000             892 ns          892 ns       785064
BM_format_to_back_inserter<std::deque<char>>/string len = 6000            14840 ns        14839 ns        47177
BM_format_to_back_inserter<std::list<char>>/string len = 6000            114940 ns       114942 ns         6095
BM_format_to_iterator/<std::array> string len = 6000                        144 ns          144 ns      4859849
BM_format_to_iterator/<std::string> string len = 6000                       106 ns          106 ns      6565564
BM_format_to_iterator/<std::vector> string len = 6000                       107 ns          107 ns      6584152
BM_format_to_iterator/<std::deque> string len = 6000                        368 ns          368 ns      1904727
BM_format/string_view len = 6000                                            919 ns          919 ns       760401
BM_format_to_back_inserter<std::string>/string_view len = 6000              917 ns          917 ns       760934
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000        880 ns          880 ns       796244
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000       14854 ns        14853 ns        47101
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000       114963 ns       114967 ns         6086
BM_format_to_iterator/<std::array> string_view len = 6000                   117 ns          117 ns      5974080
BM_format_to_iterator/<std::string> string_view len = 6000                  116 ns          116 ns      6016080
BM_format_to_iterator/<std::vector> string_view len = 6000                  116 ns          116 ns      6053780
BM_format_to_iterator/<std::deque> string_view len = 6000                   351 ns          351 ns      1993879

Comparing libcxx/benchmarks/1/write_string_comparison.bench.out to libcxx/benchmarks/2/write_string_comparison.bench.out
Benchmark                                                                              Time             CPU      Time Old      Time New       CPU Old       CPU New
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_sprintf/C string len = 6                                                         +0.0034         +0.0058             5             5             5             5
BM_format/C string len = 6                                                          +0.0484         +0.0508            53            55            52            55
BM_format_to_back_inserter<std::string>/C string len = 6                            +0.0395         +0.0424            53            55            53            55
BM_format_to_back_inserter<std::vector<char>>/C string len = 6                      +0.0220         +0.0244            70            71            70            71
BM_format_to_back_inserter<std::deque<char>>/C string len = 6                       +0.0399         +0.0424           148           154           148           154
BM_format_to_back_inserter<std::list<char>>/C string len = 6                        +0.0339         +0.0365           127           131           126           131
BM_format_to_iterator/<std::array> C string len = 6                                 +0.0494         +0.0520            43            45            43            45
BM_format_to_iterator/<std::string> C string len = 6                                +0.0539         +0.0568            44            46            43            46
BM_format_to_iterator/<std::vector> C string len = 6                                +0.0359         +0.0384            43            44            43            44
BM_format_to_iterator/<std::deque> C string len = 6                                 +0.0488         +0.0513            48            50            48            50
BM_format/string len = 6                                                            -0.0105         -0.0081            55            55            55            55
BM_format_to_back_inserter<std::string>/string len = 6                              +0.0008         +0.0036            55            55            55            55
BM_format_to_back_inserter<std::vector<char>>/string len = 6                        -0.0046         -0.0021            71            70            71            70
BM_format_to_back_inserter<std::deque<char>>/string len = 6                         +0.0066         +0.0091           153           154           153           154
BM_format_to_back_inserter<std::list<char>>/string len = 6                          +0.0291         +0.0316           128           132           128           132
BM_format_to_iterator/<std::array> string len = 6                                   -0.0030         -0.0006            45            44            44            44
BM_format_to_iterator/<std::string> string len = 6                                  +0.0045         +0.0069            45            45            45            45
BM_format_to_iterator/<std::vector> string len = 6                                  +0.0150         +0.0177            44            45            44            45
BM_format_to_iterator/<std::deque> string len = 6                                   +0.0059         +0.0084            50            51            50            51
BM_format/string_view len = 6                                                       +0.0050         +0.0075            54            55            54            55
BM_format_to_back_inserter<std::string>/string_view len = 6                         +0.0052         +0.0081            54            55            54            55
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6                   -0.0017         +0.0008            70            70            70            70
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6                    +0.0113         +0.0137           153           154           152           154
BM_format_to_back_inserter<std::list<char>>/string_view len = 6                     +0.0260         +0.0286           128           131           128           131
BM_format_to_iterator/<std::array> string_view len = 6                              -0.0006         +0.0021            44            44            44            44
BM_format_to_iterator/<std::string> string_view len = 6                             +0.0059         +0.0084            45            45            45            45
BM_format_to_iterator/<std::vector> string_view len = 6                             +0.0083         +0.0108            45            45            45            45
BM_format_to_iterator/<std::deque> string_view len = 6                              +0.0048         +0.0073            50            51            50            51
BM_sprintf/C string len = 60                                                        +0.0002         +0.0029             4             4             4             4
BM_format/C string len = 60                                                         -0.5640         -0.5629           169            74           169            74
BM_format_to_back_inserter<std::string>/C string len = 60                           -0.5592         -0.5582           167            74           167            74
BM_format_to_back_inserter<std::vector<char>>/C string len = 60                     -0.5294         -0.5282           177            83           176            83
BM_format_to_back_inserter<std::deque<char>>/C string len = 60                      -0.2591         -0.2570           383           284           382           284
BM_format_to_back_inserter<std::list<char>>/C string len = 60                       -0.0730         -0.0707          1270          1177          1267          1177
BM_format_to_iterator/<std::array> C string len = 60                                -0.6804         -0.6797           141            45           140            45
BM_format_to_iterator/<std::string> C string len = 60                               -0.6759         -0.6750           141            46           141            46
BM_format_to_iterator/<std::vector> C string len = 60                               -0.6849         -0.6841           141            45           141            45
BM_format_to_iterator/<std::deque> C string len = 60                                -0.6481         -0.6471           144            51           143            51
BM_format/string len = 60                                                           -0.0167         -0.0142            73            72            73            72
BM_format_to_back_inserter<std::string>/string len = 60                             -0.0151         -0.0127            73            72            73            72
BM_format_to_back_inserter<std::vector<char>>/string len = 60                       +0.0093         +0.0118            82            82            81            82
BM_format_to_back_inserter<std::deque<char>>/string len = 60                        -0.0003         +0.0023           279           279           279           279
BM_format_to_back_inserter<std::list<char>>/string len = 60                         +0.0025         +0.0050          1177          1180          1174          1180
BM_format_to_iterator/<std::array> string len = 60                                  +0.0046         +0.0070            45            45            44            45
BM_format_to_iterator/<std::string> string len = 60                                 +0.0050         +0.0075            45            45            45            45
BM_format_to_iterator/<std::vector> string len = 60                                 +0.0025         +0.0051            45            45            45            45
BM_format_to_iterator/<std::deque> string len = 60                                  +0.0031         +0.0056            51            51            50            51
BM_format/string_view len = 60                                                      -0.0054         -0.0030            73            72            73            72
BM_format_to_back_inserter<std::string>/string_view len = 60                        +0.0001         +0.0026            73            73            73            73
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60                  -0.0090         -0.0066            83            82            82            82
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60                   +0.0097         +0.0126           280           283           280           283
BM_format_to_back_inserter<std::list<char>>/string_view len = 60                    +0.0011         +0.0036          1176          1177          1173          1177
BM_format_to_iterator/<std::array> string_view len = 60                             +0.0001         +0.0026            44            44            44            44
BM_format_to_iterator/<std::string> string_view len = 60                            +0.0083         +0.0107            45            45            45            45
BM_format_to_iterator/<std::vector> string_view len = 60                            +0.0068         +0.0093            45            45            45            45
BM_format_to_iterator/<std::deque> string_view len = 60                             -0.0038         -0.0014            50            50            50            50
BM_sprintf/C string len = 6000                                                      +2.0230         +2.0305           114           344           114           344
BM_format/C string len = 6000                                                       -0.9169         -0.9167         11792           980         11763           980
BM_format_to_back_inserter<std::string>/C string len = 6000                         -0.9169         -0.9166         11778           979         11746           979
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000                   -0.9194         -0.9192         11715           944         11686           944
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000                    -0.4143         -0.4129         25464         14916         25403         14915
BM_format_to_back_inserter<std::list<char>>/C string len = 6000                     -0.0901         -0.0878        126044        114686        125726        114688
BM_format_to_iterator/<std::array> C string len = 6000                              -0.9852         -0.9852         10792           159         10766           159
BM_format_to_iterator/<std::string> C string len = 6000                             -0.9852         -0.9852         10791           159         10761           159
BM_format_to_iterator/<std::vector> C string len = 6000                             -0.9852         -0.9852         10775           159         10750           159
BM_format_to_iterator/<std::deque> C string len = 6000                              -0.9611         -0.9610         11242           437         11215           437
BM_format/string len = 6000                                                         +0.0108         +0.0133           919           929           917           929
BM_format_to_back_inserter<std::string>/string len = 6000                           +0.0138         +0.0167           920           933           917           933
BM_format_to_back_inserter<std::vector<char>>/string len = 6000                     +0.0041         +0.0064           888           892           886           892
BM_format_to_back_inserter<std::deque<char>>/string len = 6000                      -0.0107         -0.0082         14999         14840         14963         14839
BM_format_to_back_inserter<std::list<char>>/string len = 6000                       +0.0038         +0.0064        114504        114940        114213        114942
BM_format_to_iterator/<std::array> string len = 6000                                +0.2011         +0.2040           120           144           120           144
BM_format_to_iterator/<std::string> string len = 6000                               +0.0032         +0.0057           106           106           106           106
BM_format_to_iterator/<std::vector> string len = 6000                               +0.0057         +0.0085           106           107           106           107
BM_format_to_iterator/<std::deque> string len = 6000                                +0.0011         +0.0036           367           368           366           368
BM_format/string_view len = 6000                                                    +0.0105         +0.0130           910           919           907           919
BM_format_to_back_inserter<std::string>/string_view len = 6000                      +0.0057         +0.0081           911           917           909           917
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000                +0.0023         +0.0050           878           880           876           880
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000                 -0.0118         -0.0094         15031         14854         14994         14853
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000                  +0.0040         +0.0065        114510        114963        114219        114967
BM_format_to_iterator/<std::array> string_view len = 6000                           -0.0299         -0.0275           121           117           120           117
BM_format_to_iterator/<std::string> string_view len = 6000                          +0.0062         +0.0086           116           116           115           116
BM_format_to_iterator/<std::vector> string_view len = 6000                          +0.0034         +0.0062           115           116           115           116
BM_format_to_iterator/<std::deque> string_view len = 6000                           +0.0011         +0.0035           351           351           350           351
OVERALL_GEOMEAN                                                                     -0.2959         -0.2941             0             0             0             0

@mordante mordante requested a review from a team as a code owner August 3, 2024 09:47
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 3, 2024

@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)

Changes

The formatter specializations for _CharT* and const _CharT* typically write all elements in a loop. This format's internal functions are optimized for larger writes.

Instead of writing one element at a time conversion the range to a basic_string_view and write that instead.

For C string of 6 characters this is a bit slower, but for 60 characters it's faster. The improvements for back_inserter<std::list<_CharT>> are not as great as the others; it just gets as slow as basic_string_view<_CharT>.

Before

Benchmark Time CPU Iterations

BM_sprintf/C string len = 6 4.81 ns 4.80 ns 145890280
BM_format/C string len = 6 52.6 ns 52.4 ns 13252327
BM_format_to_back_inserter<std::string>/C string len = 6 53.0 ns 52.8 ns 13262680
BM_format_to_back_inserter<std::vector<char>>/C string len = 6 69.7 ns 69.6 ns 10045636
BM_format_to_back_inserter<std::deque<char>>/C string len = 6 148 ns 148 ns 4729368
BM_format_to_back_inserter<std::list<char>>/C string len = 6 127 ns 126 ns 5538441
BM_format_to_iterator/<std::array> C string len = 6 42.9 ns 42.8 ns 16367158
BM_format_to_iterator/<std::string> C string len = 6 43.5 ns 43.4 ns 16141644
BM_format_to_iterator/<std::vector> C string len = 6 42.9 ns 42.8 ns 16366718
BM_format_to_iterator/<std::deque> C string len = 6 47.8 ns 47.7 ns 14686488
BM_format/string len = 6 55.3 ns 55.2 ns 12696889
BM_format_to_back_inserter<std::string>/string len = 6 55.4 ns 55.2 ns 12660731
BM_format_to_back_inserter<std::vector<char>>/string len = 6 70.7 ns 70.5 ns 9927313
BM_format_to_back_inserter<std::deque<char>>/string len = 6 153 ns 153 ns 4573936
BM_format_to_back_inserter<std::list<char>>/string len = 6 128 ns 128 ns 5486033
BM_format_to_iterator/<std::array> string len = 6 44.6 ns 44.5 ns 15758122
BM_format_to_iterator/<std::string> string len = 6 44.7 ns 44.6 ns 15690226
BM_format_to_iterator/<std::vector> string len = 6 44.3 ns 44.2 ns 15715898
BM_format_to_iterator/<std::deque> string len = 6 50.3 ns 50.1 ns 13958635
BM_format/string_view len = 6 54.2 ns 54.1 ns 12929525
BM_format_to_back_inserter<std::string>/string_view len = 6 54.3 ns 54.1 ns 12929219
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6 70.0 ns 69.8 ns 10022355
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6 153 ns 152 ns 4585749
BM_format_to_back_inserter<std::list<char>>/string_view len = 6 128 ns 128 ns 5489760
BM_format_to_iterator/<std::array> string_view len = 6 44.2 ns 44.1 ns 15884839
BM_format_to_iterator/<std::string> string_view len = 6 44.8 ns 44.6 ns 15664278
BM_format_to_iterator/<std::vector> string_view len = 6 44.7 ns 44.6 ns 15716983
BM_format_to_iterator/<std::deque> string_view len = 6 50.3 ns 50.2 ns 13936091
BM_sprintf/C string len = 60 4.16 ns 4.15 ns 168764227
BM_format/C string len = 60 169 ns 169 ns 4144060
BM_format_to_back_inserter<std::string>/C string len = 60 167 ns 167 ns 4203915
BM_format_to_back_inserter<std::vector<char>>/C string len = 60 177 ns 176 ns 3965619
BM_format_to_back_inserter<std::deque<char>>/C string len = 60 383 ns 382 ns 1832531
BM_format_to_back_inserter<std::list<char>>/C string len = 60 1270 ns 1267 ns 552686
BM_format_to_iterator/<std::array> C string len = 60 141 ns 140 ns 4988441
BM_format_to_iterator/<std::string> C string len = 60 141 ns 141 ns 4956101
BM_format_to_iterator/<std::vector> C string len = 60 141 ns 141 ns 4963443
BM_format_to_iterator/<std::deque> C string len = 60 144 ns 143 ns 4893139
BM_format/string len = 60 73.4 ns 73.2 ns 9548455
BM_format_to_back_inserter<std::string>/string len = 60 73.2 ns 73.0 ns 9524524
BM_format_to_back_inserter<std::vector<char>>/string len = 60 81.6 ns 81.4 ns 8584033
BM_format_to_back_inserter<std::deque<char>>/string len = 60 279 ns 279 ns 2515146
BM_format_to_back_inserter<std::list<char>>/string len = 60 1177 ns 1174 ns 597172
BM_format_to_iterator/<std::array> string len = 60 44.5 ns 44.4 ns 15753131
BM_format_to_iterator/<std::string> string len = 60 44.7 ns 44.6 ns 15692630
BM_format_to_iterator/<std::vector> string len = 60 44.8 ns 44.7 ns 15664689
BM_format_to_iterator/<std::deque> string len = 60 50.6 ns 50.5 ns 13838617
BM_format/string_view len = 60 72.8 ns 72.6 ns 9674007
BM_format_to_back_inserter<std::string>/string_view len = 60 72.7 ns 72.6 ns 9638209
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60 82.6 ns 82.4 ns 8496602
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60 280 ns 280 ns 2508982
BM_format_to_back_inserter<std::list<char>>/string_view len = 60 1176 ns 1173 ns 597714
BM_format_to_iterator/<std::array> string_view len = 60 44.2 ns 44.1 ns 15896934
BM_format_to_iterator/<std::string> string_view len = 60 44.7 ns 44.6 ns 15695427
BM_format_to_iterator/<std::vector> string_view len = 60 44.7 ns 44.6 ns 15680899
BM_format_to_iterator/<std::deque> string_view len = 60 50.3 ns 50.1 ns 13962755
BM_sprintf/C string len = 6000 114 ns 114 ns 6170153
BM_format/C string len = 6000 11792 ns 11763 ns 59619
BM_format_to_back_inserter<std::string>/C string len = 6000 11778 ns 11746 ns 59572
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000 11715 ns 11686 ns 60053
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000 25464 ns 25403 ns 27538
BM_format_to_back_inserter<std::list<char>>/C string len = 6000 126044 ns 125726 ns 5572
BM_format_to_iterator/<std::array> C string len = 6000 10792 ns 10766 ns 64943
BM_format_to_iterator/<std::string> C string len = 6000 10791 ns 10761 ns 64918
BM_format_to_iterator/<std::vector> C string len = 6000 10775 ns 10750 ns 65149
BM_format_to_iterator/<std::deque> C string len = 6000 11242 ns 11215 ns 62542
BM_format/string len = 6000 919 ns 917 ns 763961
BM_format_to_back_inserter<std::string>/string len = 6000 920 ns 917 ns 763094
BM_format_to_back_inserter<std::vector<char>>/string len = 6000 888 ns 886 ns 793468
BM_format_to_back_inserter<std::deque<char>>/string len = 6000 14999 ns 14963 ns 46758
BM_format_to_back_inserter<std::list<char>>/string len = 6000 114504 ns 114213 ns 6130
BM_format_to_iterator/<std::array> string len = 6000 120 ns 120 ns 5823426
BM_format_to_iterator/<std::string> string len = 6000 106 ns 106 ns 6609299
BM_format_to_iterator/<std::vector> string len = 6000 106 ns 106 ns 6613867
BM_format_to_iterator/<std::deque> string len = 6000 367 ns 366 ns 1912818
BM_format/string_view len = 6000 910 ns 907 ns 771491
BM_format_to_back_inserter<std::string>/string_view len = 6000 911 ns 909 ns 770065
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000 878 ns 876 ns 794976
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000 15031 ns 14994 ns 46651
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000 114510 ns 114219 ns 6130
BM_format_to_iterator/<std::array> string_view len = 6000 121 ns 120 ns 5814249
BM_format_to_iterator/<std::string> string_view len = 6000 116 ns 115 ns 6072315
BM_format_to_iterator/<std::vector> string_view len = 6000 115 ns 115 ns 6095762
BM_format_to_iterator/<std::deque> string_view len = 6000 351 ns 350 ns 2002175

After

Benchmark Time CPU Iterations

BM_sprintf/C string len = 6 4.83 ns 4.83 ns 145502957
BM_format/C string len = 6 55.1 ns 55.1 ns 12687656
BM_format_to_back_inserter<std::string>/C string len = 6 55.1 ns 55.1 ns 12691642
BM_format_to_back_inserter<std::vector<char>>/C string len = 6 71.2 ns 71.3 ns 9819560
BM_format_to_back_inserter<std::deque<char>>/C string len = 6 154 ns 154 ns 4548709
BM_format_to_back_inserter<std::list<char>>/C string len = 6 131 ns 131 ns 5338318
BM_format_to_iterator/<std::array> C string len = 6 45.0 ns 45.0 ns 15569429
BM_format_to_iterator/<std::string> C string len = 6 45.9 ns 45.9 ns 15240594
BM_format_to_iterator/<std::vector> C string len = 6 44.4 ns 44.4 ns 15768343
BM_format_to_iterator/<std::deque> C string len = 6 50.1 ns 50.1 ns 13995837
BM_format/string len = 6 54.8 ns 54.8 ns 12738209
BM_format_to_back_inserter<std::string>/string len = 6 55.4 ns 55.4 ns 12634483
BM_format_to_back_inserter<std::vector<char>>/string len = 6 70.4 ns 70.4 ns 9948288
BM_format_to_back_inserter<std::deque<char>>/string len = 6 154 ns 154 ns 4531741
BM_format_to_back_inserter<std::list<char>>/string len = 6 132 ns 132 ns 5289798
BM_format_to_iterator/<std::array> string len = 6 44.5 ns 44.5 ns 15743437
BM_format_to_iterator/<std::string> string len = 6 44.9 ns 44.9 ns 15591961
BM_format_to_iterator/<std::vector> string len = 6 45.0 ns 45.0 ns 15541308
BM_format_to_iterator/<std::deque> string len = 6 50.5 ns 50.5 ns 13837884
BM_format/string_view len = 6 54.5 ns 54.5 ns 12833591
BM_format_to_back_inserter<std::string>/string_view len = 6 54.6 ns 54.6 ns 12818233
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6 69.9 ns 69.9 ns 10018025
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6 154 ns 154 ns 4534215
BM_format_to_back_inserter<std::list<char>>/string_view len = 6 131 ns 131 ns 5337938
BM_format_to_iterator/<std::array> string_view len = 6 44.2 ns 44.2 ns 15854695
BM_format_to_iterator/<std::string> string_view len = 6 45.0 ns 45.0 ns 15551054
BM_format_to_iterator/<std::vector> string_view len = 6 45.0 ns 45.0 ns 15567905
BM_format_to_iterator/<std::deque> string_view len = 6 50.5 ns 50.5 ns 13858261
BM_sprintf/C string len = 60 4.16 ns 4.16 ns 168066307
BM_format/C string len = 60 73.8 ns 73.8 ns 9487364
BM_format_to_back_inserter<std::string>/C string len = 60 73.7 ns 73.7 ns 9492371
BM_format_to_back_inserter<std::vector<char>>/C string len = 60 83.1 ns 83.1 ns 8399017
BM_format_to_back_inserter<std::deque<char>>/C string len = 60 284 ns 284 ns 2466510
BM_format_to_back_inserter<std::list<char>>/C string len = 60 1177 ns 1177 ns 592514
BM_format_to_iterator/<std::array> C string len = 60 44.9 ns 44.9 ns 15558172
BM_format_to_iterator/<std::string> C string len = 60 45.8 ns 45.8 ns 15283103
BM_format_to_iterator/<std::vector> C string len = 60 44.6 ns 44.6 ns 15678967
BM_format_to_iterator/<std::deque> C string len = 60 50.5 ns 50.5 ns 13839524
BM_format/string len = 60 72.2 ns 72.2 ns 9687634
BM_format_to_back_inserter<std::string>/string len = 60 72.0 ns 72.1 ns 9695746
BM_format_to_back_inserter<std::vector<char>>/string len = 60 82.3 ns 82.3 ns 8509528
BM_format_to_back_inserter<std::deque<char>>/string len = 60 279 ns 279 ns 2506108
BM_format_to_back_inserter<std::list<char>>/string len = 60 1180 ns 1180 ns 592963
BM_format_to_iterator/<std::array> string len = 60 44.7 ns 44.7 ns 15657865
BM_format_to_iterator/<std::string> string len = 60 45.0 ns 45.0 ns 15569049
BM_format_to_iterator/<std::vector> string len = 60 44.9 ns 44.9 ns 15576187
BM_format_to_iterator/<std::deque> string len = 60 50.7 ns 50.7 ns 13803188
BM_format/string_view len = 60 72.4 ns 72.4 ns 9663061
BM_format_to_back_inserter<std::string>/string_view len = 60 72.8 ns 72.8 ns 9638941
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60 81.9 ns 81.9 ns 8529931
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60 283 ns 283 ns 2471522
BM_format_to_back_inserter<std::list<char>>/string_view len = 60 1177 ns 1177 ns 594752
BM_format_to_iterator/<std::array> string_view len = 60 44.2 ns 44.2 ns 15841413
BM_format_to_iterator/<std::string> string_view len = 60 45.1 ns 45.1 ns 15546279
BM_format_to_iterator/<std::vector> string_view len = 60 45.0 ns 45.0 ns 15555756
BM_format_to_iterator/<std::deque> string_view len = 60 50.1 ns 50.1 ns 10000000
BM_sprintf/C string len = 6000 344 ns 344 ns 2037753
BM_format/C string len = 6000 980 ns 980 ns 713341
BM_format_to_back_inserter<std::string>/C string len = 6000 979 ns 979 ns 709571
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000 944 ns 944 ns 744518
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000 14916 ns 14915 ns 46875
BM_format_to_back_inserter<std::list<char>>/C string len = 6000 114686 ns 114688 ns 6110
BM_format_to_iterator/<std::array> C string len = 6000 159 ns 159 ns 4394506
BM_format_to_iterator/<std::string> C string len = 6000 159 ns 159 ns 4384577
BM_format_to_iterator/<std::vector> C string len = 6000 159 ns 159 ns 4393225
BM_format_to_iterator/<std::deque> C string len = 6000 437 ns 437 ns 1601253
BM_format/string len = 6000 929 ns 929 ns 751889
BM_format_to_back_inserter<std::string>/string len = 6000 933 ns 933 ns 752042
BM_format_to_back_inserter<std::vector<char>>/string len = 6000 892 ns 892 ns 785064
BM_format_to_back_inserter<std::deque<char>>/string len = 6000 14840 ns 14839 ns 47177
BM_format_to_back_inserter<std::list<char>>/string len = 6000 114940 ns 114942 ns 6095
BM_format_to_iterator/<std::array> string len = 6000 144 ns 144 ns 4859849
BM_format_to_iterator/<std::string> string len = 6000 106 ns 106 ns 6565564
BM_format_to_iterator/<std::vector> string len = 6000 107 ns 107 ns 6584152
BM_format_to_iterator/<std::deque> string len = 6000 368 ns 368 ns 1904727
BM_format/string_view len = 6000 919 ns 919 ns 760401
BM_format_to_back_inserter<std::string>/string_view len = 6000 917 ns 917 ns 760934
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000 880 ns 880 ns 796244
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000 14854 ns 14853 ns 47101
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000 114963 ns 114967 ns 6086
BM_format_to_iterator/<std::array> string_view len = 6000 117 ns 117 ns 5974080
BM_format_to_iterator/<std::string> string_view len = 6000 116 ns 116 ns 6016080
BM_format_to_iterator/<std::vector> string_view len = 6000 116 ns 116 ns 6053780
BM_format_to_iterator/<std::deque> string_view len = 6000 351 ns 351 ns 1993879

Comparing libcxx/benchmarks/1/write_string_comparison.bench.out to libcxx/benchmarks/2/write_string_comparison.bench.out
Benchmark Time CPU Time Old Time New CPU Old CPU New

BM_sprintf/C string len = 6 +0.0034 +0.0058 5 5 5 5
BM_format/C string len = 6 +0.0484 +0.0508 53 55 52 55
BM_format_to_back_inserter<std::string>/C string len = 6 +0.0395 +0.0424 53 55 53 55
BM_format_to_back_inserter<std::vector<char>>/C string len = 6 +0.0220 +0.0244 70 71 70 71
BM_format_to_back_inserter<std::deque<char>>/C string len = 6 +0.0399 +0.0424 148 154 148 154
BM_format_to_back_inserter<std::list<char>>/C string len = 6 +0.0339 +0.0365 127 131 126 131
BM_format_to_iterator/<std::array> C string len = 6 +0.0494 +0.0520 43 45 43 45
BM_format_to_iterator/<std::string> C string len = 6 +0.0539 +0.0568 44 46 43 46
BM_format_to_iterator/<std::vector> C string len = 6 +0.0359 +0.0384 43 44 43 44
BM_format_to_iterator/<std::deque> C string len = 6 +0.0488 +0.0513 48 50 48 50
BM_format/string len = 6 -0.0105 -0.0081 55 55 55 55
BM_format_to_back_inserter<std::string>/string len = 6 +0.0008 +0.0036 55 55 55 55
BM_format_to_back_inserter<std::vector<char>>/string len = 6 -0.0046 -0.0021 71 70 71 70
BM_format_to_back_inserter<std::deque<char>>/string len = 6 +0.0066 +0.0091 153 154 153 154
BM_format_to_back_inserter<std::list<char>>/string len = 6 +0.0291 +0.0316 128 132 128 132
BM_format_to_iterator/<std::array> string len = 6 -0.0030 -0.0006 45 44 44 44
BM_format_to_iterator/<std::string> string len = 6 +0.0045 +0.0069 45 45 45 45
BM_format_to_iterator/<std::vector> string len = 6 +0.0150 +0.0177 44 45 44 45
BM_format_to_iterator/<std::deque> string len = 6 +0.0059 +0.0084 50 51 50 51
BM_format/string_view len = 6 +0.0050 +0.0075 54 55 54 55
BM_format_to_back_inserter<std::string>/string_view len = 6 +0.0052 +0.0081 54 55 54 55
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6 -0.0017 +0.0008 70 70 70 70
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6 +0.0113 +0.0137 153 154 152 154
BM_format_to_back_inserter<std::list<char>>/string_view len = 6 +0.0260 +0.0286 128 131 128 131
BM_format_to_iterator/<std::array> string_view len = 6 -0.0006 +0.0021 44 44 44 44
BM_format_to_iterator/<std::string> string_view len = 6 +0.0059 +0.0084 45 45 45 45
BM_format_to_iterator/<std::vector> string_view len = 6 +0.0083 +0.0108 45 45 45 45
BM_format_to_iterator/<std::deque> string_view len = 6 +0.0048 +0.0073 50 51 50 51
BM_sprintf/C string len = 60 +0.0002 +0.0029 4 4 4 4
BM_format/C string len = 60 -0.5640 -0.5629 169 74 169 74
BM_format_to_back_inserter<std::string>/C string len = 60 -0.5592 -0.5582 167 74 167 74
BM_format_to_back_inserter<std::vector<char>>/C string len = 60 -0.5294 -0.5282 177 83 176 83
BM_format_to_back_inserter<std::deque<char>>/C string len = 60 -0.2591 -0.2570 383 284 382 284
BM_format_to_back_inserter<std::list<char>>/C string len = 60 -0.0730 -0.0707 1270 1177 1267 1177
BM_format_to_iterator/<std::array> C string len = 60 -0.6804 -0.6797 141 45 140 45
BM_format_to_iterator/<std::string> C string len = 60 -0.6759 -0.6750 141 46 141 46
BM_format_to_iterator/<std::vector> C string len = 60 -0.6849 -0.6841 141 45 141 45
BM_format_to_iterator/<std::deque> C string len = 60 -0.6481 -0.6471 144 51 143 51
BM_format/string len = 60 -0.0167 -0.0142 73 72 73 72
BM_format_to_back_inserter<std::string>/string len = 60 -0.0151 -0.0127 73 72 73 72
BM_format_to_back_inserter<std::vector<char>>/string len = 60 +0.0093 +0.0118 82 82 81 82
BM_format_to_back_inserter<std::deque<char>>/string len = 60 -0.0003 +0.0023 279 279 279 279
BM_format_to_back_inserter<std::list<char>>/string len = 60 +0.0025 +0.0050 1177 1180 1174 1180
BM_format_to_iterator/<std::array> string len = 60 +0.0046 +0.0070 45 45 44 45
BM_format_to_iterator/<std::string> string len = 60 +0.0050 +0.0075 45 45 45 45
BM_format_to_iterator/<std::vector> string len = 60 +0.0025 +0.0051 45 45 45 45
BM_format_to_iterator/<std::deque> string len = 60 +0.0031 +0.0056 51 51 50 51
BM_format/string_view len = 60 -0.0054 -0.0030 73 72 73 72
BM_format_to_back_inserter<std::string>/string_view len = 60 +0.0001 +0.0026 73 73 73 73
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60 -0.0090 -0.0066 83 82 82 82
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60 +0.0097 +0.0126 280 283 280 283
BM_format_to_back_inserter<std::list<char>>/string_view len = 60 +0.0011 +0.0036 1176 1177 1173 1177
BM_format_to_iterator/<std::array> string_view len = 60 +0.0001 +0.0026 44 44 44 44
BM_format_to_iterator/<std::string> string_view len = 60 +0.0083 +0.0107 45 45 45 45
BM_format_to_iterator/<std::vector> string_view len = 60 +0.0068 +0.0093 45 45 45 45
BM_format_to_iterator/<std::deque> string_view len = 60 -0.0038 -0.0014 50 50 50 50
BM_sprintf/C string len = 6000 +2.0230 +2.0305 114 344 114 344
BM_format/C string len = 6000 -0.9169 -0.9167 11792 980 11763 980
BM_format_to_back_inserter<std::string>/C string len = 6000 -0.9169 -0.9166 11778 979 11746 979
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000 -0.9194 -0.9192 11715 944 11686 944
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000 -0.4143 -0.4129 25464 14916 25403 14915
BM_format_to_back_inserter<std::list<char>>/C string len = 6000 -0.0901 -0.0878 126044 114686 125726 114688
BM_format_to_iterator/<std::array> C string len = 6000 -0.9852 -0.9852 10792 159 10766 159
BM_format_to_iterator/<std::string> C string len = 6000 -0.9852 -0.9852 10791 159 10761 159
BM_format_to_iterator/<std::vector> C string len = 6000 -0.9852 -0.9852 10775 159 10750 159
BM_format_to_iterator/<std::deque> C string len = 6000 -0.9611 -0.9610 11242 437 11215 437
BM_format/string len = 6000 +0.0108 +0.0133 919 929 917 929
BM_format_to_back_inserter<std::string>/string len = 6000 +0.0138 +0.0167 920 933 917 933
BM_format_to_back_inserter<std::vector<char>>/string len = 6000 +0.0041 +0.0064 888 892 886 892
BM_format_to_back_inserter<std::deque<char>>/string len = 6000 -0.0107 -0.0082 14999 14840 14963 14839
BM_format_to_back_inserter<std::list<char>>/string len = 6000 +0.0038 +0.0064 114504 114940 114213 114942
BM_format_to_iterator/<std::array> string len = 6000 +0.2011 +0.2040 120 144 120 144
BM_format_to_iterator/<std::string> string len = 6000 +0.0032 +0.0057 106 106 106 106
BM_format_to_iterator/<std::vector> string len = 6000 +0.0057 +0.0085 106 107 106 107
BM_format_to_iterator/<std::deque> string len = 6000 +0.0011 +0.0036 367 368 366 368
BM_format/string_view len = 6000 +0.0105 +0.0130 910 919 907 919
BM_format_to_back_inserter<std::string>/string_view len = 6000 +0.0057 +0.0081 911 917 909 917
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000 +0.0023 +0.0050 878 880 876 880
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000 -0.0118 -0.0094 15031 14854 14994 14853
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000 +0.0040 +0.0065 114510 114963 114219 114967
BM_format_to_iterator/<std::array> string_view len = 6000 -0.0299 -0.0275 121 117 120 117
BM_format_to_iterator/<std::string> string_view len = 6000 +0.0062 +0.0086 116 116 115 116
BM_format_to_iterator/<std::vector> string_view len = 6000 +0.0034 +0.0062 115 116 115 116
BM_format_to_iterator/<std::deque> string_view len = 6000 +0.0011 +0.0035 351 351 350 351
OVERALL_GEOMEAN -0.2959 -0.2941 0 0 0 0


Full diff: https://github.com/llvm/llvm-project/pull/101805.diff

1 Files Affected:

  • (modified) libcxx/include/__format/formatter_string.h (+7-25)
diff --git a/libcxx/include/__format/formatter_string.h b/libcxx/include/__format/formatter_string.h
index dee2b3ad073a5..a30e563992ece 100644
--- a/libcxx/include/__format/formatter_string.h
+++ b/libcxx/include/__format/formatter_string.h
@@ -64,32 +64,14 @@ struct _LIBCPP_TEMPLATE_VIS formatter<const _CharT*, _CharT> : public __formatte
   template <class _FormatContext>
   _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _CharT* __str, _FormatContext& __ctx) const {
     _LIBCPP_ASSERT_INTERNAL(__str, "The basic_format_arg constructor should have prevented an invalid pointer.");
-
-    __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx);
-#  if _LIBCPP_STD_VER >= 23
-    if (_Base::__parser_.__type_ == __format_spec::__type::__debug)
-      return __formatter::__format_escaped_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
-#  endif
-
-    // When using a center or right alignment and the width option the length
-    // of __str must be known to add the padding upfront. This case is handled
-    // by the base class by converting the argument to a basic_string_view.
+    // Converting the input to a basic_string_view means the data is looped over twice;
+    // - once to determine the lenght, and
+    // - once to process the data.
     //
-    // When using left alignment and the width option the padding is added
-    // after outputting __str so the length can be determined while outputting
-    // __str. The same holds true for the precision, during outputting __str it
-    // can be validated whether the precision threshold has been reached. For
-    // now these optimizations aren't implemented. Instead the base class
-    // handles these options.
-    // TODO FMT Implement these improvements.
-    if (__specs.__has_width() || __specs.__has_precision())
-      return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs);
-
-    // No formatting required, copy the string to the output.
-    auto __out_it = __ctx.out();
-    while (*__str)
-      *__out_it++ = *__str++;
-    return __out_it;
+    // This sounds slower than writing the output directly. However internally
+    // the output algorithms have optimizations for "bulk" operations. This
+    // means processing the data twice is faster than processing it once.
+    return _Base::format(basic_string_view<_CharT>(__str), __ctx);
   }
 };
 

@mordante mordante force-pushed the users/mordante/format_performance__benchmarks branch from d4376a4 to 7d63915 Compare September 17, 2024 15:21
@mordante mordante force-pushed the users/mordante/format_performance__c_string_optimization branch from f46ff67 to 9c7c298 Compare September 17, 2024 15:22
@philnik777
Copy link
Contributor

It's also worth noting that compilers can constant-fold strlen, so in cases where the string is known this doesn't even result in multiple iterations.

@mordante mordante force-pushed the users/mordante/format_performance__benchmarks branch 2 times, most recently from 8db9ff2 to 161b481 Compare October 6, 2024 14:11
Base automatically changed from users/mordante/format_performance__benchmarks to main October 6, 2024 16:19
The formatter specializations for _CharT* and const _CharT* typically
write all elements in a loop. This format's internal functions are
optimized for larger writes.

Instead of writing one element at a time conversion the range to a
basic_string_view and write that instead.

For C string of 6 characters this is a bit slower, but for 60 characters
it's faster. The improvements for back_inserter<std::list<_CharT>> are not
as great as the others; it just gets as slow as basic_string_view<_CharT>.

Before
---------------------------------------------------------------------------------------------------------------
Benchmark                                                                     Time             CPU   Iterations
---------------------------------------------------------------------------------------------------------------
BM_sprintf/C string len = 6                                                4.81 ns         4.80 ns    145890280
BM_format/C string len = 6                                                 52.6 ns         52.4 ns     13252327
BM_format_to_back_inserter<std::string>/C string len = 6                   53.0 ns         52.8 ns     13262680
BM_format_to_back_inserter<std::vector<char>>/C string len = 6             69.7 ns         69.6 ns     10045636
BM_format_to_back_inserter<std::deque<char>>/C string len = 6               148 ns          148 ns      4729368
BM_format_to_back_inserter<std::list<char>>/C string len = 6                127 ns          126 ns      5538441
BM_format_to_iterator/<std::array> C string len = 6                        42.9 ns         42.8 ns     16367158
BM_format_to_iterator/<std::string> C string len = 6                       43.5 ns         43.4 ns     16141644
BM_format_to_iterator/<std::vector> C string len = 6                       42.9 ns         42.8 ns     16366718
BM_format_to_iterator/<std::deque> C string len = 6                        47.8 ns         47.7 ns     14686488
BM_format/string len = 6                                                   55.3 ns         55.2 ns     12696889
BM_format_to_back_inserter<std::string>/string len = 6                     55.4 ns         55.2 ns     12660731
BM_format_to_back_inserter<std::vector<char>>/string len = 6               70.7 ns         70.5 ns      9927313
BM_format_to_back_inserter<std::deque<char>>/string len = 6                 153 ns          153 ns      4573936
BM_format_to_back_inserter<std::list<char>>/string len = 6                  128 ns          128 ns      5486033
BM_format_to_iterator/<std::array> string len = 6                          44.6 ns         44.5 ns     15758122
BM_format_to_iterator/<std::string> string len = 6                         44.7 ns         44.6 ns     15690226
BM_format_to_iterator/<std::vector> string len = 6                         44.3 ns         44.2 ns     15715898
BM_format_to_iterator/<std::deque> string len = 6                          50.3 ns         50.1 ns     13958635
BM_format/string_view len = 6                                              54.2 ns         54.1 ns     12929525
BM_format_to_back_inserter<std::string>/string_view len = 6                54.3 ns         54.1 ns     12929219
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6          70.0 ns         69.8 ns     10022355
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6            153 ns          152 ns      4585749
BM_format_to_back_inserter<std::list<char>>/string_view len = 6             128 ns          128 ns      5489760
BM_format_to_iterator/<std::array> string_view len = 6                     44.2 ns         44.1 ns     15884839
BM_format_to_iterator/<std::string> string_view len = 6                    44.8 ns         44.6 ns     15664278
BM_format_to_iterator/<std::vector> string_view len = 6                    44.7 ns         44.6 ns     15716983
BM_format_to_iterator/<std::deque> string_view len = 6                     50.3 ns         50.2 ns     13936091
BM_sprintf/C string len = 60                                               4.16 ns         4.15 ns    168764227
BM_format/C string len = 60                                                 169 ns          169 ns      4144060
BM_format_to_back_inserter<std::string>/C string len = 60                   167 ns          167 ns      4203915
BM_format_to_back_inserter<std::vector<char>>/C string len = 60             177 ns          176 ns      3965619
BM_format_to_back_inserter<std::deque<char>>/C string len = 60              383 ns          382 ns      1832531
BM_format_to_back_inserter<std::list<char>>/C string len = 60              1270 ns         1267 ns       552686
BM_format_to_iterator/<std::array> C string len = 60                        141 ns          140 ns      4988441
BM_format_to_iterator/<std::string> C string len = 60                       141 ns          141 ns      4956101
BM_format_to_iterator/<std::vector> C string len = 60                       141 ns          141 ns      4963443
BM_format_to_iterator/<std::deque> C string len = 60                        144 ns          143 ns      4893139
BM_format/string len = 60                                                  73.4 ns         73.2 ns      9548455
BM_format_to_back_inserter<std::string>/string len = 60                    73.2 ns         73.0 ns      9524524
BM_format_to_back_inserter<std::vector<char>>/string len = 60              81.6 ns         81.4 ns      8584033
BM_format_to_back_inserter<std::deque<char>>/string len = 60                279 ns          279 ns      2515146
BM_format_to_back_inserter<std::list<char>>/string len = 60                1177 ns         1174 ns       597172
BM_format_to_iterator/<std::array> string len = 60                         44.5 ns         44.4 ns     15753131
BM_format_to_iterator/<std::string> string len = 60                        44.7 ns         44.6 ns     15692630
BM_format_to_iterator/<std::vector> string len = 60                        44.8 ns         44.7 ns     15664689
BM_format_to_iterator/<std::deque> string len = 60                         50.6 ns         50.5 ns     13838617
BM_format/string_view len = 60                                             72.8 ns         72.6 ns      9674007
BM_format_to_back_inserter<std::string>/string_view len = 60               72.7 ns         72.6 ns      9638209
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60         82.6 ns         82.4 ns      8496602
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60           280 ns          280 ns      2508982
BM_format_to_back_inserter<std::list<char>>/string_view len = 60           1176 ns         1173 ns       597714
BM_format_to_iterator/<std::array> string_view len = 60                    44.2 ns         44.1 ns     15896934
BM_format_to_iterator/<std::string> string_view len = 60                   44.7 ns         44.6 ns     15695427
BM_format_to_iterator/<std::vector> string_view len = 60                   44.7 ns         44.6 ns     15680899
BM_format_to_iterator/<std::deque> string_view len = 60                    50.3 ns         50.1 ns     13962755
BM_sprintf/C string len = 6000                                              114 ns          114 ns      6170153
BM_format/C string len = 6000                                             11792 ns        11763 ns        59619
BM_format_to_back_inserter<std::string>/C string len = 6000               11778 ns        11746 ns        59572
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000         11715 ns        11686 ns        60053
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000          25464 ns        25403 ns        27538
BM_format_to_back_inserter<std::list<char>>/C string len = 6000          126044 ns       125726 ns         5572
BM_format_to_iterator/<std::array> C string len = 6000                    10792 ns        10766 ns        64943
BM_format_to_iterator/<std::string> C string len = 6000                   10791 ns        10761 ns        64918
BM_format_to_iterator/<std::vector> C string len = 6000                   10775 ns        10750 ns        65149
BM_format_to_iterator/<std::deque> C string len = 6000                    11242 ns        11215 ns        62542
BM_format/string len = 6000                                                 919 ns          917 ns       763961
BM_format_to_back_inserter<std::string>/string len = 6000                   920 ns          917 ns       763094
BM_format_to_back_inserter<std::vector<char>>/string len = 6000             888 ns          886 ns       793468
BM_format_to_back_inserter<std::deque<char>>/string len = 6000            14999 ns        14963 ns        46758
BM_format_to_back_inserter<std::list<char>>/string len = 6000            114504 ns       114213 ns         6130
BM_format_to_iterator/<std::array> string len = 6000                        120 ns          120 ns      5823426
BM_format_to_iterator/<std::string> string len = 6000                       106 ns          106 ns      6609299
BM_format_to_iterator/<std::vector> string len = 6000                       106 ns          106 ns      6613867
BM_format_to_iterator/<std::deque> string len = 6000                        367 ns          366 ns      1912818
BM_format/string_view len = 6000                                            910 ns          907 ns       771491
BM_format_to_back_inserter<std::string>/string_view len = 6000              911 ns          909 ns       770065
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000        878 ns          876 ns       794976
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000       15031 ns        14994 ns        46651
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000       114510 ns       114219 ns         6130
BM_format_to_iterator/<std::array> string_view len = 6000                   121 ns          120 ns      5814249
BM_format_to_iterator/<std::string> string_view len = 6000                  116 ns          115 ns      6072315
BM_format_to_iterator/<std::vector> string_view len = 6000                  115 ns          115 ns      6095762
BM_format_to_iterator/<std::deque> string_view len = 6000                   351 ns          350 ns      2002175

After
---------------------------------------------------------------------------------------------------------------
Benchmark                                                                     Time             CPU   Iterations
---------------------------------------------------------------------------------------------------------------
BM_sprintf/C string len = 6                                                4.83 ns         4.83 ns    145502957
BM_format/C string len = 6                                                 55.1 ns         55.1 ns     12687656
BM_format_to_back_inserter<std::string>/C string len = 6                   55.1 ns         55.1 ns     12691642
BM_format_to_back_inserter<std::vector<char>>/C string len = 6             71.2 ns         71.3 ns      9819560
BM_format_to_back_inserter<std::deque<char>>/C string len = 6               154 ns          154 ns      4548709
BM_format_to_back_inserter<std::list<char>>/C string len = 6                131 ns          131 ns      5338318
BM_format_to_iterator/<std::array> C string len = 6                        45.0 ns         45.0 ns     15569429
BM_format_to_iterator/<std::string> C string len = 6                       45.9 ns         45.9 ns     15240594
BM_format_to_iterator/<std::vector> C string len = 6                       44.4 ns         44.4 ns     15768343
BM_format_to_iterator/<std::deque> C string len = 6                        50.1 ns         50.1 ns     13995837
BM_format/string len = 6                                                   54.8 ns         54.8 ns     12738209
BM_format_to_back_inserter<std::string>/string len = 6                     55.4 ns         55.4 ns     12634483
BM_format_to_back_inserter<std::vector<char>>/string len = 6               70.4 ns         70.4 ns      9948288
BM_format_to_back_inserter<std::deque<char>>/string len = 6                 154 ns          154 ns      4531741
BM_format_to_back_inserter<std::list<char>>/string len = 6                  132 ns          132 ns      5289798
BM_format_to_iterator/<std::array> string len = 6                          44.5 ns         44.5 ns     15743437
BM_format_to_iterator/<std::string> string len = 6                         44.9 ns         44.9 ns     15591961
BM_format_to_iterator/<std::vector> string len = 6                         45.0 ns         45.0 ns     15541308
BM_format_to_iterator/<std::deque> string len = 6                          50.5 ns         50.5 ns     13837884
BM_format/string_view len = 6                                              54.5 ns         54.5 ns     12833591
BM_format_to_back_inserter<std::string>/string_view len = 6                54.6 ns         54.6 ns     12818233
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6          69.9 ns         69.9 ns     10018025
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6            154 ns          154 ns      4534215
BM_format_to_back_inserter<std::list<char>>/string_view len = 6             131 ns          131 ns      5337938
BM_format_to_iterator/<std::array> string_view len = 6                     44.2 ns         44.2 ns     15854695
BM_format_to_iterator/<std::string> string_view len = 6                    45.0 ns         45.0 ns     15551054
BM_format_to_iterator/<std::vector> string_view len = 6                    45.0 ns         45.0 ns     15567905
BM_format_to_iterator/<std::deque> string_view len = 6                     50.5 ns         50.5 ns     13858261
BM_sprintf/C string len = 60                                               4.16 ns         4.16 ns    168066307
BM_format/C string len = 60                                                73.8 ns         73.8 ns      9487364
BM_format_to_back_inserter<std::string>/C string len = 60                  73.7 ns         73.7 ns      9492371
BM_format_to_back_inserter<std::vector<char>>/C string len = 60            83.1 ns         83.1 ns      8399017
BM_format_to_back_inserter<std::deque<char>>/C string len = 60              284 ns          284 ns      2466510
BM_format_to_back_inserter<std::list<char>>/C string len = 60              1177 ns         1177 ns       592514
BM_format_to_iterator/<std::array> C string len = 60                       44.9 ns         44.9 ns     15558172
BM_format_to_iterator/<std::string> C string len = 60                      45.8 ns         45.8 ns     15283103
BM_format_to_iterator/<std::vector> C string len = 60                      44.6 ns         44.6 ns     15678967
BM_format_to_iterator/<std::deque> C string len = 60                       50.5 ns         50.5 ns     13839524
BM_format/string len = 60                                                  72.2 ns         72.2 ns      9687634
BM_format_to_back_inserter<std::string>/string len = 60                    72.0 ns         72.1 ns      9695746
BM_format_to_back_inserter<std::vector<char>>/string len = 60              82.3 ns         82.3 ns      8509528
BM_format_to_back_inserter<std::deque<char>>/string len = 60                279 ns          279 ns      2506108
BM_format_to_back_inserter<std::list<char>>/string len = 60                1180 ns         1180 ns       592963
BM_format_to_iterator/<std::array> string len = 60                         44.7 ns         44.7 ns     15657865
BM_format_to_iterator/<std::string> string len = 60                        45.0 ns         45.0 ns     15569049
BM_format_to_iterator/<std::vector> string len = 60                        44.9 ns         44.9 ns     15576187
BM_format_to_iterator/<std::deque> string len = 60                         50.7 ns         50.7 ns     13803188
BM_format/string_view len = 60                                             72.4 ns         72.4 ns      9663061
BM_format_to_back_inserter<std::string>/string_view len = 60               72.8 ns         72.8 ns      9638941
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60         81.9 ns         81.9 ns      8529931
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60           283 ns          283 ns      2471522
BM_format_to_back_inserter<std::list<char>>/string_view len = 60           1177 ns         1177 ns       594752
BM_format_to_iterator/<std::array> string_view len = 60                    44.2 ns         44.2 ns     15841413
BM_format_to_iterator/<std::string> string_view len = 60                   45.1 ns         45.1 ns     15546279
BM_format_to_iterator/<std::vector> string_view len = 60                   45.0 ns         45.0 ns     15555756
BM_format_to_iterator/<std::deque> string_view len = 60                    50.1 ns         50.1 ns     10000000
BM_sprintf/C string len = 6000                                              344 ns          344 ns      2037753
BM_format/C string len = 6000                                               980 ns          980 ns       713341
BM_format_to_back_inserter<std::string>/C string len = 6000                 979 ns          979 ns       709571
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000           944 ns          944 ns       744518
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000          14916 ns        14915 ns        46875
BM_format_to_back_inserter<std::list<char>>/C string len = 6000          114686 ns       114688 ns         6110
BM_format_to_iterator/<std::array> C string len = 6000                      159 ns          159 ns      4394506
BM_format_to_iterator/<std::string> C string len = 6000                     159 ns          159 ns      4384577
BM_format_to_iterator/<std::vector> C string len = 6000                     159 ns          159 ns      4393225
BM_format_to_iterator/<std::deque> C string len = 6000                      437 ns          437 ns      1601253
BM_format/string len = 6000                                                 929 ns          929 ns       751889
BM_format_to_back_inserter<std::string>/string len = 6000                   933 ns          933 ns       752042
BM_format_to_back_inserter<std::vector<char>>/string len = 6000             892 ns          892 ns       785064
BM_format_to_back_inserter<std::deque<char>>/string len = 6000            14840 ns        14839 ns        47177
BM_format_to_back_inserter<std::list<char>>/string len = 6000            114940 ns       114942 ns         6095
BM_format_to_iterator/<std::array> string len = 6000                        144 ns          144 ns      4859849
BM_format_to_iterator/<std::string> string len = 6000                       106 ns          106 ns      6565564
BM_format_to_iterator/<std::vector> string len = 6000                       107 ns          107 ns      6584152
BM_format_to_iterator/<std::deque> string len = 6000                        368 ns          368 ns      1904727
BM_format/string_view len = 6000                                            919 ns          919 ns       760401
BM_format_to_back_inserter<std::string>/string_view len = 6000              917 ns          917 ns       760934
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000        880 ns          880 ns       796244
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000       14854 ns        14853 ns        47101
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000       114963 ns       114967 ns         6086
BM_format_to_iterator/<std::array> string_view len = 6000                   117 ns          117 ns      5974080
BM_format_to_iterator/<std::string> string_view len = 6000                  116 ns          116 ns      6016080
BM_format_to_iterator/<std::vector> string_view len = 6000                  116 ns          116 ns      6053780
BM_format_to_iterator/<std::deque> string_view len = 6000                   351 ns          351 ns      1993879

Comparing libcxx/benchmarks/1/write_string_comparison.bench.out to libcxx/benchmarks/2/write_string_comparison.bench.out
Benchmark                                                                              Time             CPU      Time Old      Time New       CPU Old       CPU New
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_sprintf/C string len = 6                                                         +0.0034         +0.0058             5             5             5             5
BM_format/C string len = 6                                                          +0.0484         +0.0508            53            55            52            55
BM_format_to_back_inserter<std::string>/C string len = 6                            +0.0395         +0.0424            53            55            53            55
BM_format_to_back_inserter<std::vector<char>>/C string len = 6                      +0.0220         +0.0244            70            71            70            71
BM_format_to_back_inserter<std::deque<char>>/C string len = 6                       +0.0399         +0.0424           148           154           148           154
BM_format_to_back_inserter<std::list<char>>/C string len = 6                        +0.0339         +0.0365           127           131           126           131
BM_format_to_iterator/<std::array> C string len = 6                                 +0.0494         +0.0520            43            45            43            45
BM_format_to_iterator/<std::string> C string len = 6                                +0.0539         +0.0568            44            46            43            46
BM_format_to_iterator/<std::vector> C string len = 6                                +0.0359         +0.0384            43            44            43            44
BM_format_to_iterator/<std::deque> C string len = 6                                 +0.0488         +0.0513            48            50            48            50
BM_format/string len = 6                                                            -0.0105         -0.0081            55            55            55            55
BM_format_to_back_inserter<std::string>/string len = 6                              +0.0008         +0.0036            55            55            55            55
BM_format_to_back_inserter<std::vector<char>>/string len = 6                        -0.0046         -0.0021            71            70            71            70
BM_format_to_back_inserter<std::deque<char>>/string len = 6                         +0.0066         +0.0091           153           154           153           154
BM_format_to_back_inserter<std::list<char>>/string len = 6                          +0.0291         +0.0316           128           132           128           132
BM_format_to_iterator/<std::array> string len = 6                                   -0.0030         -0.0006            45            44            44            44
BM_format_to_iterator/<std::string> string len = 6                                  +0.0045         +0.0069            45            45            45            45
BM_format_to_iterator/<std::vector> string len = 6                                  +0.0150         +0.0177            44            45            44            45
BM_format_to_iterator/<std::deque> string len = 6                                   +0.0059         +0.0084            50            51            50            51
BM_format/string_view len = 6                                                       +0.0050         +0.0075            54            55            54            55
BM_format_to_back_inserter<std::string>/string_view len = 6                         +0.0052         +0.0081            54            55            54            55
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6                   -0.0017         +0.0008            70            70            70            70
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6                    +0.0113         +0.0137           153           154           152           154
BM_format_to_back_inserter<std::list<char>>/string_view len = 6                     +0.0260         +0.0286           128           131           128           131
BM_format_to_iterator/<std::array> string_view len = 6                              -0.0006         +0.0021            44            44            44            44
BM_format_to_iterator/<std::string> string_view len = 6                             +0.0059         +0.0084            45            45            45            45
BM_format_to_iterator/<std::vector> string_view len = 6                             +0.0083         +0.0108            45            45            45            45
BM_format_to_iterator/<std::deque> string_view len = 6                              +0.0048         +0.0073            50            51            50            51
BM_sprintf/C string len = 60                                                        +0.0002         +0.0029             4             4             4             4
BM_format/C string len = 60                                                         -0.5640         -0.5629           169            74           169            74
BM_format_to_back_inserter<std::string>/C string len = 60                           -0.5592         -0.5582           167            74           167            74
BM_format_to_back_inserter<std::vector<char>>/C string len = 60                     -0.5294         -0.5282           177            83           176            83
BM_format_to_back_inserter<std::deque<char>>/C string len = 60                      -0.2591         -0.2570           383           284           382           284
BM_format_to_back_inserter<std::list<char>>/C string len = 60                       -0.0730         -0.0707          1270          1177          1267          1177
BM_format_to_iterator/<std::array> C string len = 60                                -0.6804         -0.6797           141            45           140            45
BM_format_to_iterator/<std::string> C string len = 60                               -0.6759         -0.6750           141            46           141            46
BM_format_to_iterator/<std::vector> C string len = 60                               -0.6849         -0.6841           141            45           141            45
BM_format_to_iterator/<std::deque> C string len = 60                                -0.6481         -0.6471           144            51           143            51
BM_format/string len = 60                                                           -0.0167         -0.0142            73            72            73            72
BM_format_to_back_inserter<std::string>/string len = 60                             -0.0151         -0.0127            73            72            73            72
BM_format_to_back_inserter<std::vector<char>>/string len = 60                       +0.0093         +0.0118            82            82            81            82
BM_format_to_back_inserter<std::deque<char>>/string len = 60                        -0.0003         +0.0023           279           279           279           279
BM_format_to_back_inserter<std::list<char>>/string len = 60                         +0.0025         +0.0050          1177          1180          1174          1180
BM_format_to_iterator/<std::array> string len = 60                                  +0.0046         +0.0070            45            45            44            45
BM_format_to_iterator/<std::string> string len = 60                                 +0.0050         +0.0075            45            45            45            45
BM_format_to_iterator/<std::vector> string len = 60                                 +0.0025         +0.0051            45            45            45            45
BM_format_to_iterator/<std::deque> string len = 60                                  +0.0031         +0.0056            51            51            50            51
BM_format/string_view len = 60                                                      -0.0054         -0.0030            73            72            73            72
BM_format_to_back_inserter<std::string>/string_view len = 60                        +0.0001         +0.0026            73            73            73            73
BM_format_to_back_inserter<std::vector<char>>/string_view len = 60                  -0.0090         -0.0066            83            82            82            82
BM_format_to_back_inserter<std::deque<char>>/string_view len = 60                   +0.0097         +0.0126           280           283           280           283
BM_format_to_back_inserter<std::list<char>>/string_view len = 60                    +0.0011         +0.0036          1176          1177          1173          1177
BM_format_to_iterator/<std::array> string_view len = 60                             +0.0001         +0.0026            44            44            44            44
BM_format_to_iterator/<std::string> string_view len = 60                            +0.0083         +0.0107            45            45            45            45
BM_format_to_iterator/<std::vector> string_view len = 60                            +0.0068         +0.0093            45            45            45            45
BM_format_to_iterator/<std::deque> string_view len = 60                             -0.0038         -0.0014            50            50            50            50
BM_sprintf/C string len = 6000                                                      +2.0230         +2.0305           114           344           114           344
BM_format/C string len = 6000                                                       -0.9169         -0.9167         11792           980         11763           980
BM_format_to_back_inserter<std::string>/C string len = 6000                         -0.9169         -0.9166         11778           979         11746           979
BM_format_to_back_inserter<std::vector<char>>/C string len = 6000                   -0.9194         -0.9192         11715           944         11686           944
BM_format_to_back_inserter<std::deque<char>>/C string len = 6000                    -0.4143         -0.4129         25464         14916         25403         14915
BM_format_to_back_inserter<std::list<char>>/C string len = 6000                     -0.0901         -0.0878        126044        114686        125726        114688
BM_format_to_iterator/<std::array> C string len = 6000                              -0.9852         -0.9852         10792           159         10766           159
BM_format_to_iterator/<std::string> C string len = 6000                             -0.9852         -0.9852         10791           159         10761           159
BM_format_to_iterator/<std::vector> C string len = 6000                             -0.9852         -0.9852         10775           159         10750           159
BM_format_to_iterator/<std::deque> C string len = 6000                              -0.9611         -0.9610         11242           437         11215           437
BM_format/string len = 6000                                                         +0.0108         +0.0133           919           929           917           929
BM_format_to_back_inserter<std::string>/string len = 6000                           +0.0138         +0.0167           920           933           917           933
BM_format_to_back_inserter<std::vector<char>>/string len = 6000                     +0.0041         +0.0064           888           892           886           892
BM_format_to_back_inserter<std::deque<char>>/string len = 6000                      -0.0107         -0.0082         14999         14840         14963         14839
BM_format_to_back_inserter<std::list<char>>/string len = 6000                       +0.0038         +0.0064        114504        114940        114213        114942
BM_format_to_iterator/<std::array> string len = 6000                                +0.2011         +0.2040           120           144           120           144
BM_format_to_iterator/<std::string> string len = 6000                               +0.0032         +0.0057           106           106           106           106
BM_format_to_iterator/<std::vector> string len = 6000                               +0.0057         +0.0085           106           107           106           107
BM_format_to_iterator/<std::deque> string len = 6000                                +0.0011         +0.0036           367           368           366           368
BM_format/string_view len = 6000                                                    +0.0105         +0.0130           910           919           907           919
BM_format_to_back_inserter<std::string>/string_view len = 6000                      +0.0057         +0.0081           911           917           909           917
BM_format_to_back_inserter<std::vector<char>>/string_view len = 6000                +0.0023         +0.0050           878           880           876           880
BM_format_to_back_inserter<std::deque<char>>/string_view len = 6000                 -0.0118         -0.0094         15031         14854         14994         14853
BM_format_to_back_inserter<std::list<char>>/string_view len = 6000                  +0.0040         +0.0065        114510        114963        114219        114967
BM_format_to_iterator/<std::array> string_view len = 6000                           -0.0299         -0.0275           121           117           120           117
BM_format_to_iterator/<std::string> string_view len = 6000                          +0.0062         +0.0086           116           116           115           116
BM_format_to_iterator/<std::vector> string_view len = 6000                          +0.0034         +0.0062           115           116           115           116
BM_format_to_iterator/<std::deque> string_view len = 6000                           +0.0011         +0.0035           351           351           350           351
OVERALL_GEOMEAN                                                                     -0.2959         -0.2941             0             0             0             0
@mordante mordante force-pushed the users/mordante/format_performance__c_string_optimization branch from 9c7c298 to efa7aff Compare October 6, 2024 16:26
@mordante mordante merged commit 7f65377 into main Oct 6, 2024
64 checks passed
@mordante mordante deleted the users/mordante/format_performance__c_string_optimization branch October 6, 2024 19:20
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 6, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-android running on sanitizer-buildbot-android while building libcxx at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/2983

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (210 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (35 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (120 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (1 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (127 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (142 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (25373 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (25376 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

skipping tests on aarch64

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

@@@STEP_FAILURE@@@
Step 9 (run cmake) failure: run cmake (failure)
...
-- Performing Test HAVE_CXX_FLAG_COVERAGE
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Failed
-- Compiling and running to test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- compiled but failed to run
CMake Warning at /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/third-party/benchmark/CMakeLists.txt:319 (message):
  Using std::regex with exceptions disabled is not fully supported
-- Compiling and running to test HAVE_STEADY_CLOCK
-- Performing Test HAVE_POSIX_REGEX -- compiled but failed to run
CMake Warning at /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/third-party/benchmark/CMakeLists.txt:319 (message):
  Using std::regex with exceptions disabled is not fully supported
-- Compiling and running to test HAVE_STEADY_CLOCK
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Compiling and running to test HAVE_POSIX_REGEX
-- Performing Test HAVE_STEADY_CLOCK -- compiled but failed to run
-- Performing Test HAVE_STEADY_CLOCK -- compiled but failed to run
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Compiling and running to test HAVE_PTHREAD_AFFINITY
-- Found Threads: TRUE  
-- Compiling and running to test HAVE_PTHREAD_AFFINITY
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring done (25.5s)
-- Configuring done (25.5s)
-- Performing Test HAVE_POSIX_REGEX -- compiled but failed to run
-- Compiling and running to test HAVE_STEADY_CLOCK
CMake Warning at /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm-project/third-party/benchmark/CMakeLists.txt:319 (message):
  Using std::regex with exceptions disabled is not fully supported
-- Performing Test HAVE_STEADY_CLOCK -- compiled but failed to run
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Compiling and running to test HAVE_PTHREAD_AFFINITY
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring done (26.3s)
-- Generating done (2.7s)
-- Generating done (2.8s)
-- Build files have been written to: /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm_build_android_aarch64
-- Build files have been written to: /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm_build_android_i686
-- Generating done (2.6s)
-- Build files have been written to: /var/lib/buildbot/sanitizer-buildbot6/sanitizer-x86_64-linux-android/build/llvm_build_android_arm
Step 10 (build android/aarch64) failure: build android/aarch64 (failure)
...
[609/654] Building CXX object lib/DebugInfo/Symbolize/CMakeFiles/LLVMSymbolize.dir/SymbolizableObjectFile.cpp.o
[610/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/AArch64TargetParser.cpp.o
[611/654] Building CXX object lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLLexer.cpp.o
[612/654] Building CXX object lib/DebugInfo/PDB/CMakeFiles/LLVMDebugInfoPDB.dir/Native/SymbolCache.cpp.o
[613/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/TargetParser.cpp.o
[614/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/SubtargetFeature.cpp.o
[615/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/RISCVTargetParser.cpp.o
[616/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/ArchitectureSet.cpp.o
[617/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Architecture.cpp.o
[618/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/X86TargetParser.cpp.o
[619/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/PackedVersion.cpp.o
[620/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/Triple.cpp.o
[621/654] Building CXX object lib/TargetParser/CMakeFiles/LLVMTargetParser.dir/RISCVISAInfo.cpp.o
[622/654] Linking CXX static library lib/libLLVMTargetParser.a
[623/654] Linking CXX static library lib/libLLVMBinaryFormat.a
[624/654] Linking CXX static library lib/libLLVMCore.a
[625/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Platform.cpp.o
[626/654] Linking CXX static library lib/libLLVMBitReader.a
[627/654] Linking CXX static library lib/libLLVMMC.a
[628/654] Linking CXX static library lib/libLLVMMCParser.a
[629/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Symbol.cpp.o
[630/654] Building Opts.inc...
[631/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextAPIError.cpp.o
[632/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/RecordVisitor.cpp.o
[633/654] Building CXX object lib/DebugInfo/Symbolize/CMakeFiles/LLVMSymbolize.dir/Symbolize.cpp.o
[634/654] Building CXX object lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/Parser.cpp.o
[635/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Target.cpp.o
[636/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/SymbolSet.cpp.o
[637/654] Building CXX object tools/llvm-symbolizer/CMakeFiles/llvm-symbolizer.dir/llvm-symbolizer-driver.cpp.o
[638/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/Utils.cpp.o
[639/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/RecordsSlice.cpp.o
[640/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/InterfaceFile.cpp.o
[641/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextStubCommon.cpp.o
[642/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextStubV5.cpp.o
[643/654] Building CXX object tools/llvm-symbolizer/CMakeFiles/llvm-symbolizer.dir/llvm-symbolizer.cpp.o
[644/654] Building CXX object lib/TextAPI/CMakeFiles/LLVMTextAPI.dir/TextStub.cpp.o
[645/654] Linking CXX static library lib/libLLVMTextAPI.a
[646/654] Building CXX object lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLParser.cpp.o
[647/654] Linking CXX static library lib/libLLVMAsmParser.a
[648/654] Linking CXX static library lib/libLLVMIRReader.a
[649/654] Linking CXX static library lib/libLLVMObject.a
[650/654] Linking CXX static library lib/libLLVMDebugInfoDWARF.a
[651/654] Linking CXX static library lib/libLLVMDebugInfoPDB.a
[652/654] Linking CXX static library lib/libLLVMSymbolize.a
[653/654] Linking CXX static library lib/libLLVMDebuginfod.a
[654/654] Linking CXX executable bin/llvm-symbolizer
ninja: Entering directory `compiler_rt_build_android_aarch64'
ninja: error: loading 'build.ninja': No such file or directory

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
Step 19 (run instrumented asan tests [arm/aosp_coral-userdebug/AOSP.MASTER]) failure: run instrumented asan tests [arm/aosp_coral-userdebug/AOSP.MASTER] (failure)
...
[       OK ] AddressSanitizer.CallocReturnsZeroMem (11 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (335 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (22 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (253 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (1 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (296 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (301 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (66199 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (66203 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

skipping tests on aarch64

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
Serial 17031FQCB00176
Step 24 (run instrumented asan tests [arm/bluejay-userdebug/TQ3A.230805.001]) failure: run instrumented asan tests [arm/bluejay-userdebug/TQ3A.230805.001] (failure)
...
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN      ] AddressSanitizer.IgnoreTest
[       OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN      ] AddressSanitizer.SignalTest
[       OK ] AddressSanitizer.SignalTest (210 ms)
[ RUN      ] AddressSanitizer.ReallocTest
[       OK ] AddressSanitizer.ReallocTest (35 ms)
[ RUN      ] AddressSanitizer.WrongFreeTest
[       OK ] AddressSanitizer.WrongFreeTest (120 ms)
[ RUN      ] AddressSanitizer.LongJmpTest
[       OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN      ] AddressSanitizer.ThreadStackReuseTest
[       OK ] AddressSanitizer.ThreadStackReuseTest (1 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN      ] AddressSanitizer.UseThenFreeThenUseTest
[       OK ] AddressSanitizer.UseThenFreeThenUseTest (127 ms)
[ RUN      ] AddressSanitizer.FileNameInGlobalReportTest
[       OK ] AddressSanitizer.FileNameInGlobalReportTest (142 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN      ] AddressSanitizer.MlockTest
[       OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN      ] AddressSanitizer.LongDoubleNegativeTest
[       OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[----------] 19 tests from AddressSanitizer (25373 ms total)

[----------] Global test environment tear-down
[==========] 22 tests from 2 test suites ran. (25376 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

skipping tests on aarch64

How to reproduce locally: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild
program finished with exit code 1
elapsedTime=1721.331137

Kyvangka1610 added a commit to Kyvangka1610/llvm-project that referenced this pull request Oct 7, 2024
* commit 'FETCH_HEAD':
  [X86] getIntImmCostInst - pull out repeated Imm.getBitWidth() calls. NFC.
  [X86] Add test coverage for llvm#111323
  [Driver] Use empty multilib file in another test (llvm#111352)
  [clang][OpenMP][test] Use x86_64-linux-gnu triple for test referencing avx512f feature (llvm#111337)
  [doc] Fix Kaleidoscope tutorial chapter 3 code snippet and full listing discrepancies (llvm#111289)
  [Flang][OpenMP] Improve entry block argument creation and binding (llvm#110267)
  [x86] combineMul - handle 0/-1 KnownBits cases before MUL_IMM logic (REAPPLIED)
  [llvm-dis] Fix non-deterministic disassembly across multiple inputs (llvm#110988)
  [lldb][test] TestDataFormatterLibcxxOptionalSimulator.py: change order of ifdefs
  [lldb][test] Add libcxx-simulators test for std::optional (llvm#111133)
  [x86] combineMul - use computeKnownBits directly to find MUL_IMM constant splat. (REAPPLIED)
  Reland "[lldb][test] TestDataFormatterLibcxxStringSimulator.py: add new padding layout" (llvm#111123)
  Revert "[x86] combineMul - use computeKnownBits directly to find MUL_IMM constant splat."
  update_test_checks: fix a simple regression  (llvm#111347)
  [LegalizeVectorTypes] Always widen fabs (llvm#111298)
  [lsan] Make ReportUnsuspendedThreads return bool also for Fuchsia
  [mlir][vector] Add more tests for ConvertVectorToLLVM (6/n) (llvm#111121)
  [bazel] port 9144fed
  [SystemZ] Remove inlining threshold multiplier. (llvm#106058)
  [LegalizeVectorTypes] When widening don't check for libcalls if promoted (llvm#111297)
  [clang][Driver] Improve multilib custom error reporting (llvm#110804)
  [clang][Driver] Rename "FatalError" key to "Error" in multilib.yaml (llvm#110804)
  [LLVM][Maintainers] Update release managers (llvm#111164)
  [Clang][Driver] Add option to provide path for multilib's YAML config file (llvm#109640)
  [LoopVectorize] Remove redundant code in emitSCEVChecks (llvm#111132)
  [AMDGPU] Only emit SCOPE_SYS global_wb (llvm#110636)
  [ELF] Change Ctx::target to unique_ptr (llvm#111260)
  [ELF] Pass Ctx & to some free functions
  [RISCV] Only disassemble fcvtmod.w.d if the rounding mode is rtz. (llvm#111308)
  [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d76 (llvm#111277)
  [ELF] Pass Ctx & to InputFile
  [clang-format] Add AlignFunctionDeclarations to AlignConsecutiveDeclarations (llvm#108241)
  [AMDGPU] Support preloading hidden kernel arguments (llvm#98861)
  [ELF] Move static nextGroupId isInGroup to LinkerDriver
  [clangd] Add ArgumentLists config option under Completion (llvm#111322)
  [ELF] Pass Ctx & to SyntheticSections
  [ELF] Pass Ctx & to Symbols
  [ELF] Pass Ctx & to Symbols
  [ELF] getRelocTargetVA: pass Ctx and Relocation. NFC
  [clang-tidy] Avoid capturing a local variable in a static lambda in UseRangesCheck (llvm#111282)
  [VPlan] Use pointer to member 0 as VPInterleaveRecipe's pointer arg. (llvm#106431)
  [clangd] Simplify ternary expressions with std::optional::value_or (NFC) (llvm#111309)
  [libc++][format][2/3] Optimizes c-string arguments. (llvm#101805)
  [RISCV] Combine RVBUnary and RVKUnary into classes that are more similar to ALU(W)_r(r/i). NFC (llvm#111279)
  [ELF] Pass Ctx & to InputFiles
  [libc] GPU RPC interface: add return value to `rpc_host_call` (llvm#111288)

Signed-off-by: kyvangka1610 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants