Skip to content

Very low throughput #51

Description

@nh2
main = do
  let rs :: [Word8]
      rs = randoms (mkStdGen 42)

  print $ sum $ map (\x -> fromIntegral x :: Int) $ take 10000000 rs

gives me around 5 MB/s on my laptop.

main = do
  let rs :: [Int]
      rs = randoms (mkStdGen 42)

  print $ sum $ map (\x -> fromIntegral x :: Int) $ take 10000000 rs

gives me around 8 MB/s on my laptop.

This is very slow for a pseudorandom number generator.

/dev/urandom gives me 230 MB on the same machine.

Activity

  1. nh2 commented on Nov 25, 2018

    @nh2
    MemberAuthor

    I found this issue when trying to test my lz4 binding with QuickCheck (tests would take forever when generating reasonably sized input), so I started measuring the speed of random gens.

  2. idontgetoutmuch commented on Nov 25, 2018

    @idontgetoutmuch
    Member

    @nh2 don't use this package - see

    #31
    #29
    https://ghc.haskell.org/trac/ghc/ticket/2280

    Throughput is not its only problem.

    I have made suggestions for replacing it and deprecating it.

    @nh2 I thought QuickCheck used tf-random these days on account of this package not implementing split int a sensible way? Are you sure QuickCheck is actually using this package?

    FYI - this runs about x10 faster for me.

    import System.Random.MWC
    
    main :: IO ()
    main2 = do
        gen <- create
    
        let testUniform 0 !x = return (x :: Int)
            testUniform n x = do
                y <- uniform gen
                testUniform (n - 1) (x + y)
    
        total <- testUniform 10000000 0
        print total
    
  3. cartazio commented on Nov 25, 2018

    @cartazio
    Contributor
  4. cartazio commented on Nov 25, 2018

    @cartazio
    Contributor
  5. nh2 commented on Nov 25, 2018

    @nh2
    MemberAuthor

    I thought QuickCheck used tf-random these days on account of this package not implementing split int a sensible way? Are you sure QuickCheck is actually using this package?

    I know, but tf-random is equally at least the way quickcheck-instances uses it, see: nick8325/quickcheck#234

    don't use this package

    @idontgetoutmuch I'm aware of the issues but I cannot easily patch it out all the way down to QuickCheck -- as you can imagine, this issue is just a sidetrack in my 5-levels deep recursion stack of what I actually want to work on :)

    master has a much more performant and good quality algorithm

    @cartazio This is nice, but for it to have a real impact it must be on Hackage and libs like QuickCheck must be using it.

    What is the application domain / way of using rngs you have going on?

    Right now, I just want QuickCheck to work at reasonable speeds. I'm writing an lz4 binding and wanted to test it with it, for which I need to generate lots of input ByteStrings, including large ones. I found that I cannot write a Gen ByteString that exceeds 8 MB/s, which makes my tests take forever.

    So I started measuring the underlying libraries (random and tf-random and found that they are all slow).

    Pcg should be way faster / better quality

    Good hint, appreciated!

    I have already implemented a workaround based on pcg-random (with a seed and target length generated by QuickCheck's choose) to generate the ByteStrings. I've measured that this works at ~300 MB/s, even faster than /dev/urandom.

    But of course having to do this using this workaround isn't great; I am already many hours into a complete side-project -- I had expected this stuff to just work (tm).

    could you please just stop being involved on tickets and let’s just get you off the maintainer list?

    Let's not get bitter about things, we all want the same thing in the end. It is understandable that people are frustrated because a core component that they must rely on (by choice or dependency) doesn't work out of the box, for a long time. I too am frustrated because I didn't expect I'd be spending many hours of my weekend dealing with random number generation.

    Pointing out problems with the current state is also a useful contribution (this is what my ticket here does, too). Let's not get discouraged by it, but rather encouraged to get things fixed.

  6. cartazio commented on Nov 25, 2018

    @cartazio
    Contributor
  7. ecthiender commented on Apr 25, 2019

    @ecthiender

    @cartazio was this pcg version released? Just curious to know if the fast version has landed on hackage.

  8. cartazio commented on Apr 25, 2019

    @cartazio
    Contributor

    atm not yet, but the split-mix and pcg packages on hackage should be decent today
    (i had to work though how to make sure stuff is forward migrable, and now its on my release queue again once i suss things out with relevant CLC members)

  9. cartazio commented on Apr 25, 2019

    @cartazio
    Contributor

    this is definitely my fault, but its one of those things where i need to / want to navigate evolving the ecosystem and breakages carefully

  10. ecthiender commented on Apr 26, 2019

    @ecthiender

    Ok, thanks for the update.

  11. lehins commented on May 26, 2020

    @lehins
    Contributor

    For anyone that is interested in this ticket, apparently it has been a problem for 12 years almost 15 years and there is finally a solution in #61

    All we are waiting for now is getting it reviewed and released, right @cartazio ?

  12. cartazio commented on May 26, 2020

    @cartazio
    Contributor
  13. lehins commented on Jun 23, 2020

    @lehins
    Contributor

    @nh2 I am really happy to let you know that this is no longer an issue! 😄 random-1.2 is now on hackage.

    Let me know the results if you get a chance to try out your throughput benchmark comparison against the /dev/urandom ;)

  14. added this to the 1.2.0 milestone on Jan 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions