1

I have studied swift compiler ( swiftc ) I just make one swift file written about sorting algorithms. ( radix, merge, quick, heap .. ) and then I compiled with or without optimization flags ( -O , -wmo ) and checked time by using flag (-driver-time-compilation)

⬇️ result1 - not using optimization flag enter image description here

⬇️ result2 - using optimization flag. enter image description here

but result1 was taken 0.3544 wall time. I think wall time is really taken time.

and result2 was taken 0.9037 wall time.

I think using optimization flag should be more faster than not using.

Can you help me understand why is this?
I want to reduce compile time only using swiftc.

HyunSu
  • 155
  • 7
  • 1
    Those timings look like the time it takes to compile the file, not running the resulting optimized executable. Optimizations take time and the compiler has to work harder to make them, it's normal that the compilation takes longer when optimizing – Dario Petrillo Mar 27 '21 at 10:26
  • @DarioPetrillo oh.!! It hit me! Thank you so much! so, Wow.. Exectued time using optimization is so faster than not using. wow... And Then I wonder is there any disadvantage by using optimization ? – HyunSu Mar 27 '21 at 11:03
  • 1
    Potentially a bigger executable, depending on what the optimization does, but in most cases it's just better – Dario Petrillo Mar 27 '21 at 11:03
  • @DarioPetrillo Oh thank you! I found and got it disadvantage of using optimization. Thank you. Why wouldn't you answer my question? I want to pick you. Thank you so much. – HyunSu Mar 27 '21 at 11:20
  • I just added my answer – Dario Petrillo Mar 27 '21 at 12:15

1 Answers1

3

The times you are showing are compilation times, not execution times. Optimizations take time and the compiler has to work harder to complete them, it's completely normal that compilation takes longer when optimizing the code.

This is in general the intended behaviour, one small disadvantage is the larger executable size that can be produced, but that's generally not an issue

Dario Petrillo
  • 980
  • 7
  • 15