HyunSu
HyunSu

Reputation: 165

swiftc compile time is more slow when using -O than not using

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.

Upvotes: 1

Views: 209

Answers (1)

Dario Petrillo
Dario Petrillo

Reputation: 1113

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

Upvotes: 3

Related Questions