cloud_007's blog

By cloud_007, history, 22 months ago, In English

Hi!

I've found this strange thing(maybe not that strange who already knows it). Can anyone explain why this takes less time and memory complexity in C++14 and C++17 compilers than in the C++20 compiler? I've attached the time and memory complexity of this problem below.

Submission Link: C++ 17 C++ 14 C++ 20

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
22 months ago, # |
  Vote: I like it +3 Vote: I do not like it

It's not different time/memory complexity. That'd usually be something like 10000% difference, not 50%. It's different time/memory, which is normal because different compilers produce different code which consumes different resources. If it was always the same, there'd be no point in having those different compilers, no?

  • »
    »
    22 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I understand, what I don't is the memory complexity of 120836KB & 187964KB in 17 and 20 respectively.

    • »
      »
      »
      22 months ago, # ^ |
        Vote: I like it +10 Vote: I do not like it

      14/17 are 32 bit, 20 is 64 bit. Any pointers (eg return addresses on stack) are therefore twice as big. On top of that the stack usage for a function is generally higher in x64 due to different alignment / calling conventions.

    • »
      »
      »
      22 months ago, # ^ |
        Vote: I like it +13 Vote: I do not like it

      You can't have memory complexity of 187964KB or 2GB or whatever... Memory complexity can be $$$O(n^2)$$$, $$$O(n)$$$, $$$O(1)$$$, etc.