C++(gcc-4.3.2) VS C++(gcc-4.0.0-8)

I have observed there is significant performance difference between C++(gcc-4.3.2) and C++(gcc-4.0.0-8)
Don’t know the reason but C++(gcc-4.0.0-8) is significantly slower than C++(gcc-4.3.2).
MY one solution which was getting tle got accpeted in C++(gcc-4.3.2).

also for others solution I have seen performance boost.

2 Likes

Alright so what do you want to say? Should it be the opposite way? :smiley:

1 Like

I was sharing my observation :smiley:

There may be many reasons for one compiler version being slower than the other. It may depend on some parameters like the load on the judge server at the time of the submission, the data structure that is used in the submission etc.

I have an example where its the complete opposite (GCC 4.3.2 is slower than GCC 4.0.0-8). See submission Id 2349591 and 2349588. Both the solutions are ditto copy of each other, but GCC 4.3.2 gives a TLE while GCC 4.0.0-8 gives an AC. On investigation we found that the submission was using a Linked list. Linked lists are slower than a Vectors or Array for every operation. You can refer the below links for reference.

1.) http://stackoverflow.com/questions/10332789/stdlist-vs-stdvector-iteration

2.) http://www.baptiste-wicht.com/2012/12/cpp-benchmark-vector-list-deque/

Linked list was not efficient for this problem, the user should have used some other faster data structure. It is very difficult for the problem setter and tester to approximate time limits for every such case as consistency in execution time between compiler versions can not be guaranteed.

Well, adding to what @tojochacko mentioned, I would like to add that it also depends on the optimizations that is done by the compiler, and there are several changes every time gcc comes up with a newer version.

And I observed the behavior when I went deeper into the mechanism of gcc, and reading the dump files it produces during compilation, the gimple and control flow graphs that are created all internally. After a lot of research, it was found that different versions might have different optimizations for the same program.

This has been asked on stackoverflow.

gcc 4.0.0 was released in year 2005 while gcc 4.3.2 came in year 2008. So apart from language changes there are compiler improvements and bug-fixes as well in newer version. That explains the performance difference.

BTW there is no reason of using older version. Man here we are asking for gcc 4.8!

If you want real reasons for the difference you should look at “General Optimizer Improvements” in change log of gcc 4.1, gcc 4.2 and gcc 4.3. I will copy some of them below-

  • GCC can now partition functions in sections of hot and cold code. This can significantly improve performance due to better instruction cache locality. This feature works best together with profile feedback driven optimization.
  • During feedback directed optimizations, the expected block size the memcpy, memset and bzero functions operate on is discovered and for cases of commonly used small sizes, specialized inline code is generated.
  • Transition of basic block profiling to tree level implementation has been completed. The new implementation should be considerably more reliable and can be used to drive higher level optimizations, such as inlining.
  • etc.
//