nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
724 stars 121 forks source link

Can classify be done more efficiently? #190

Closed camilstaps closed 6 years ago

camilstaps commented 6 years ago

When I run the below code, the tests run fast but after it says "OK, passed 1000000 tests." it takes 1-2s to show the distribution of the classes.

quickCheck (withMaxSuccess 1000000 (\x -> classify (even x) "even" $ classify (odd x) "odd" $ even x || odd x))

That leads me to think that a list of classes or even a list of test cases is kept in memory until the end of all tests. I'm not sure if this is correct, but it is consistent with experiments on larger tests of mine, where using a higher withMaxSuccess uses more memory, and more memory is allocated as the run progresses (and it cannot be because of the size of the test cases, they are still small). Is that necessary for something? For the classes, it would seem easiest to keep a map of classes and a simple count of how often they occurred.

Lysxia commented 6 years ago

That looks like it, the labels go in a big list. At the end it is traversed several times to count disjoint sets of labels...

nick8325 commented 6 years ago

I don't recall if there was a good reason for doing it like this, but I will see if I can fix it. (Patches welcome, of course!)

nick8325 commented 6 years ago

Fixed!

camilstaps commented 6 years ago

Excellent!