TooDumbToWin's blog

By TooDumbToWin, history, 3 years ago, In English,

I ran these codes in custom invocation and got weird running times.


#include<bits/stdc++.h> using namespace std; int main(){ //Hi for(int i=0;i<5000000;i++)cout<<i<<" "; return 0; }

Run time: 2448 ms


#include<bits/stdc++.h> using namespace std; int main(){ for(int i=0;i<5000000;i++)cout<<i<<" "; return 0; }

Run time: 2901 ms

Can anyone explain why adding comment is having significant impact on running times?

PS: Changing comment affected run time slightly as well.

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

»
3 years ago, # |
  Vote: I like it +24 Vote: I do not like it

I guess it should just be difference between each runs. And codeforces caches your submission so if you submit one multiple times, it will return the same result.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    "I guess it should just be difference between each runs." I didn't get you. Can you please rephrase the statement?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Due to dynamic CPU frequency, server load or some other reasons, time required for processing the same data by identical program may varies. As a result, several runs of a program may result different time consumed.

      Sorry for my bad English, hope this makes more sense.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        As Laakeri has mentioned, the difference is quite high (450 ms).

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
          Rev. 2   Vote: I like it +5 Vote: I do not like it

          This extent of difference is possible, at least on my machine (the result of running OP's program):

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            So I can get AC/TLE with same code depending upon server status? That's not really good. :/

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +23 Vote: I do not like it

    Online judge should not be so unstable that time difference between runs of the same program is over 400 ms.

»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Tried it 8 times. If I change the comment for "Petr" it works.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    CodeForces doesn't recompile your code if it's the same (at least in some time window)

    so tried 8 times may mean that result just was cached

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Took that into account. I tried it on different windows and making changes on the code.