Smash the Code - Swift too slow without optimization

I’m trying to make a naive brute force solution for Smash the Code contest and I found Swift way too slow without optimization. I believe my algorithm have complexity O(6^N * (H*W)log(HW) ), where H=12, W=6, N=5.
Profiling on my local machine gives me:
with [-Onone]:
“I: Time elapsed for turn 0: 316 ms”
“I: Time elapsed for turn 1: 311 ms”
“I: Time elapsed for turn 2: 359 ms”
with [-O]:
“I: Time elapsed for turn 0: 19 ms”
“I: Time elapsed for turn 1: 16 ms”
“I: Time elapsed for turn 2: 18 ms”

Please take a look on this stackoverflow answer:

Being forced to use ineffective optimization options makes coders like me think of using raw unsafe/unmanaged data for their solution which produces ugly code and counter-productive experience. Difference between debug/release optimization in swift is huge compared to other languages. Therefore making [-O] optimization available for swift will make performance-hungry contests like this more fair.

As I understand, basically we have three options for optimization:
[-Onone]: generating code for debug purpose with no optimizations
[-O]: default release optimization
[-Ofast]: unchecked, unsafe optimization
-Ofast makes swift execute differently, debug logging is available for both -Onone and -O options, The only difference I found so far is assertions, which is completely ignored with -O option.

3 Likes

Maybe try reducing the complexity of your code? 6^N doesn’t sound good.