http://www.perlmonks.org?node_id=649294


in reply to Subroutine overhead in Perl

Hmmm...

It's seems like your grid_check subroutine will always have speed issues, as you have two foreach loops nested within foreach loops, which then recurse back into to the grid_check function.

Yikes. What is this, like a Big O of O(N3)? I'm betting that the Java solution used a different algorithm that did not use this design. This becomes a huge problem as N increases.

As to how to fix it, I don't know how to play Sudoku, so I cannot comment on a fix. Perhaps you might improve efficiency by exiting the foreach loops as quickly as possible so that you don't iterate on remaining unusable values?

I'm certain this code can be improved, so maybe other Monks can provide enlightenment.

Update: Changed Big O terminology

Where do you want *them* to go today?