Блог пользователя Vicennial

Автор Vicennial, история, 10 лет назад, По-английски

I had to use recursion+strings for a problem in a contest and I stumbled upon this irregularity.

Sample Code 'A' with strings:

Using input=5
Results:
G++ 11 5.1.0 = 7987 ms, 2044 KB
G++ 14 6.2.0 = 889 ms, 1856 KB
------------------------------------

Sample Code 'B' without strings:

Using input=6
Results:
G++ 11 5.1.0 = 3026 ms, 2012 KB
G++ 14 6.2.0 = 2995 ms, 1868 KB

To test it yourself, head over to http://codeforces.me/problemset/customtest

Why is there such a huge difference when strings are used?

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -26 Проголосовать: не нравится

Do you know the difference between void f(string s) and void f(string &s)?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

In g++ version 5.4.1 both programs (-std=c++11 or -std=c++14) have the same speed. So it probably is just an optimization the compiler introduced in version 5.2-4.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -23 Проголосовать: не нравится

It might be that on codeforces, G++14 code runs on a faster processor. Optimisations at compiler level don't make sense.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +34 Проголосовать: не нравится

I believe it's due to a different compiler version, not 11 or 14 standard.

I have tested it on my computer on g++ 6.3 (both g++11 and g++14 ran around 1s) and g++ 4.9 (both ran around 1.3s). On ideone g++ and g++14 (both from version 6.3) run in the same time while g++ (but version 4.3.2) is slower (output is clock ticks).

In all these runs there was no difference between runtimes of g++, g++11 and g++14, while there were differences between versions. I didn't get to test 5.1 though.