Skip to content
This repository
Browse code

More elegant version of match2. SLOWDOWN by a factor of 100! :-(

  • Loading branch information...
commit b6f58699258ef68ddee21a1346bd184465aaaba2 1 parent 9cf0ace
Harald Bögeholz authored September 03, 2012

Showing 1 changed file with 8 additions and 9 deletions. Show diff stats Hide diff stats

  1. 17  slitherlink.hs
17  slitherlink.hs
@@ -120,10 +120,10 @@ narrow seed state = if Set.null seed then Just state else
@@ -145,11 +145,10 @@ matchl i state x = if inRange (bounds state) i

6 notes on commit b6f5869

Harald Bögeholz
Owner

This change made the program dramatically slower and I don't understand why. For the (default) 10x10 test case this version needs 55 seconds while the version in the parent commit needs .33 seconds on my machine.
I thought I had made only a cosmetic change expressing things more elegantly.
Any ideas why there is such a huge performance impact would be greatly appreciated.

Stefan Wehr

Did you compile with -O2? Just a wild guess but optimization may have quite a drastic effect with GHC.

Joachim Breitner

From a first glance I notice that in the original code, there is any (... && ...) xs while the new code has all (... any ... xs) fps, so you are reversing the conjunction and disjunction. Not sure if it is sound, but maybe that already caused the difference. Is othercell large?

Harald Bögeholz
Owner

Thanks a lot, @nomeata ! You are absolutely right and that was the problem. I have fixed match2 and it is now fast again.

Harald Bögeholz
Owner

And thanks to @skogsbaer too. Yes, I am compiling with -O2.

Gregory Collins

Right: "any" terminates after the first match, while "all" has to scan the entire list.

Please sign in to comment.
Something went wrong with that request. Please try again.