public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113835] New: compiling std::vector with const size in C++20 is slow
@ 2024-02-08 17:11 pobrn at protonmail dot com
  2024-02-09  6:58 ` [Bug libstdc++/113835] [13/14 Regression] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pobrn at protonmail dot com @ 2024-02-08 17:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113835

            Bug ID: 113835
           Summary: compiling std::vector with const size in C++20 is slow
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pobrn at protonmail dot com
  Target Milestone: ---

Consider the following code:

    #include <vector>
    const std::size_t N = 1'000'000;
    std::vector<int> x(N);
    int main() {}

Then:

    $ hyperfine 'g++ -std=c++20 -O2 x.cpp' 'g++ -std=c++17 -O2 x.cpp'
    Benchmark 1: g++ -std=c++20 -O2 x.cpp
      Time (mean ± σ):      4.945 s ±  0.116 s    [User: 4.676 s, System: 0.229
s]
      Range (min … max):    4.770 s …  5.178 s    10 runs

    Benchmark 2: g++ -std=c++17 -O2 x.cpp
      Time (mean ± σ):     491.3 ms ±  24.0 ms    [User: 440.9 ms, System: 46.3
ms]
      Range (min … max):   465.6 ms … 538.0 ms    10 runs

    Summary
      g++ -std=c++17 -O2 x.cpp ran
       10.07 ± 0.55 times faster than g++ -std=c++20 -O2 x.cpp

If you remove the `const` from `N`, the runtime will be closer to C++17 levels.

`-ftime-report` suggests that "constant expression evaluation" is the reason. I
imagine this is related to C++20 making std::vector constexpr.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-21  9:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 17:11 [Bug c++/113835] New: compiling std::vector with const size in C++20 is slow pobrn at protonmail dot com
2024-02-09  6:58 ` [Bug libstdc++/113835] [13/14 Regression] " rguenth at gcc dot gnu.org
2024-02-09 13:42 ` redi at gcc dot gnu.org
2024-02-12 10:45 ` jakub at gcc dot gnu.org
2024-02-12 15:00 ` ppalka at gcc dot gnu.org
2024-02-12 15:28 ` ppalka at gcc dot gnu.org
2024-02-12 15:38 ` jakub at gcc dot gnu.org
2024-03-07 20:40 ` law at gcc dot gnu.org
2024-05-21  9:19 ` [Bug libstdc++/113835] [13/14/15 " jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).