haskell-hedgehog icon indicating copy to clipboard operation
haskell-hedgehog copied to clipboard

Looking for some way to generate large vectors efficiently

Open newhoggy opened this issue 6 years ago • 2 comments

hedgehog seems to be slow generating large vectors in CI environment. This is perhaps because the CI environment is underpowered compared to my development environment, but the problem of generating a Vector Word64 up to size 16384 100 times doesn't sound like it ought to be too expensive an operation.

The vector generator is:

storableVector :: (MonadGen m, DVS.Storable a) => Range Int -> m a -> m (DVS.Vector a)
storableVector r g = DVS.fromList <$> G.list r g

Here is an example of the above scenario taking 41s:

https://circleci.com/gh/haskell-works/hw-balancedparens/1233

newhoggy avatar Feb 27 '20 21:02 newhoggy

The following hacky implementation is proving to be a lot faster:

storableVectorWord64 :: MonadGen m => Range Int -> m (DVS.Vector Word64)
storableVectorWord64 r = fromGenT $ do
  n <- integral_ r
  GenT $ \_ seed ->
    return $ flip (DVS.unfoldrN n) seed $ \s ->
      let (w, sb) = nextWord64 s in Just (w, sb)

newhoggy avatar Feb 27 '20 23:02 newhoggy

It would be nice to have a vector support in hedgehog that can generate vectors fast and can accept an arbitrary generator.

Would there be interest in something like this?

Also would anyone be able to offer some help?

I have confusion around to properly negotiate the monad stack and I haven't been able find examples in the code to make a working example.

newhoggy avatar Feb 27 '20 23:02 newhoggy