-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lower memory use of instance Arbitrary Double
/Float
.
#419
base: master
Are you sure you want to change the base?
Lower memory use of instance Arbitrary Double
/Float
.
#419
Conversation
ghci> flip traverse [1..100] $ \_ -> length . show <$> generate (scale (const 100000000) $ (arbitrary :: Gen Double)) on master, this is slow and memory hungry. (I couldn't figure out how to pass RTS options to ghci using `cabal repl`, but I've seen it take over 5 minutes and 10 GB.) With this commit it's fast. Closes nick8325#418.
src/Test/QuickCheck/Arbitrary.hs
Outdated
i <- chooseInt (0, n) | ||
pure (fromRational (streamNth i rationalUniverse)) | ||
pure (fromRational (streamNth (min i 256) rationalUniverse)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a strange distribution of min i 256
. Better to do i <- chooseInt (0, min n 256)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't sure about that. I went with this on grounds "larger size means you still get bigger things here on average", but happy to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with the old code is that larger size => n is almost always bigger than 256 => the result is almost always the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that makes sense.
on master, this is slow and memory hungry. (I couldn't figure out how to pass RTS options to ghci using
cabal repl
, but I've seen it take over 5 minutes and 10 GB.) With this commit it's fast.Closes #418.