FPC vs GCC vs Clang, base code taken from #27252: extreme differences
Original Reporter info from Mantis: leledumbo_cool@yahoo.co.id @leledumbo
-
Reporter name: Mario Ray Mahardhika
Original Reporter info from Mantis: leledumbo_cool@yahoo.co.id @leledumbo
- Reporter name: Mario Ray Mahardhika
Description:
I looked at the code in report #27252 (closed) and try to reproduce relevant data, with varying optimization levels. I also add Clang to the benchmark. The result (please use monospace font):
+----------------+-------------------+-------------------+-------------------+
| OPT \ Compiler | FPC | GCC | Clang |
+----------------+-------------------+-------------------+-------------------+
| | real 1m40.574s | real 1m35.097s | real 1m33.196s |
| -O0 | user 1m40.510s | user 1m35.040s | user 1m33.143s |
| | sys 0m0.003s | sys 0m0.000s | sys 0m0.000s |
+----------------+-------------------+-------------------+-------------------+
| | real 1m38.589s | real 0m36.168s | real 0m45.336s |
| -O1 | user 1m38.527s | user 0m36.147s | user 0m45.310s |
| | sys 0m0.007s | sys 0m0.000s | sys 0m0.000s |
+----------------+-------------------+-------------------+-------------------+
| | real 1m5.050s | real 0m19.675s | real 0m43.960s |
| -O2 | user 1m5.010s | user 0m19.663s | user 0m43.933s |
| | sys 0m0.000s | sys 0m0.000s | sys 0m0.000s |
+----------------+-------------------+-------------------+-------------------+
| | real 1m4.639s | real 0m1.415s | real 0m1.114s |
| -O3 | user 1m4.600s | user 0m1.413s | user 0m1.110s |
| | sys 0m0.000s | sys 0m0.000s | sys 0m0.000s |
+----------------+-------------------+-------------------+-------------------+
| | real 1m4.374s | | |
| -O4 | user 1m4.337s | = -O3 | = -O3 |
| | sys 0m0.000s | | |
+----------------+-------------------+-------------------+-------------------+
The gap between GCC and Clang are not so big, but with FPC are surprisingly big. The assembler output doesn't look suspicious but it looks like both C compilers have managed to find some early loop exit calculation. I attach all three assembler output as references and to clarify my guess.
Steps to reproduce:
Compile program from the mentioned bug report id using specified optimization levels, and execute with time command.
Additional information:
Changing Integer to LongInt improves a bit. The code can go down to 56 seconds on at least -O3. Changing it to Int64 improves further to 52 seconds on -O2. I guess this is due to FPC always calculates in 64-bit.
Mantis conversion info:
- Mantis ID: 27281
- OS: linux
- OS Build: Rolling release
- Build: 29428
- Platform: x86_64
- Version: 2.7.1
- Monitored by: » s_tarassov (Serguei Tarassov), » Vincent (Vincent Snijders), » parcel (Do-wan Kim)