Repository : ssh://darcs.haskell.org//srv/darcs/packages/random On branch : master
http://hackage.haskell.org/trac/ghc/changeset/b2443d5529cd54401f0b4680bd0496c9bf80ef9f >--------------------------------------------------------------- commit b2443d5529cd54401f0b4680bd0496c9bf80ef9f Author: Ryan Newton <[email protected]> Date: Fri Sep 30 01:54:44 2011 -0400 Fixed bug in Ticket 5501. But there appears to be a significant performance regression that warrants further investigation. >--------------------------------------------------------------- DEVLOG.md | 37 +++++++++++++++++++++++++++++++++++++ README.md | 5 ++++- System/Random.hs | 8 ++++---- random.cabal | 7 +++++-- tests/Makefile | 7 +++++++ 5 files changed, 57 insertions(+), 7 deletions(-) diff --git a/DEVLOG.md b/DEVLOG.md index c1fd749..6e0b28d 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -157,3 +157,40 @@ First validating in the context of a slightly stale GHC head (7.3.20110727) on a mac. +[2011.09.30] Redoing timings after bugfix in version 1.0.1.1 +------------------------------------------------------------ + +It looks like there has been serious performance regression (3.33ghz +nehalem still). + + How many random numbers can we generate in a second on one thread? + Cost of rdtsc (ffi call): 38 + Approx getCPUTime calls per second: 7,121 + Approx clock frequency: 96,610,524 + First, timing System.Random.next: + 148,133,038 randoms generated [constant zero gen] ~ 0.65 cycles/int + 12,656,455 randoms generated [System.Random stdGen/next] ~ 7.63 cycles/int + + Second, timing System.Random.random at different types: + 676,066 randoms generated [System.Random Ints] ~ 143 cycles/int + 3,917,247 randoms generated [System.Random Word16] ~ 24.66 cycles/int + 2,231,460 randoms generated [System.Random Floats] ~ 43.29 cycles/int + 2,269,993 randoms generated [System.Random CFloats] ~ 42.56 cycles/int + 686,363 randoms generated [System.Random Doubles] ~ 141 cycles/int + 2,165,679 randoms generated [System.Random CDoubles] ~ 44.61 cycles/int + 713,702 randoms generated [System.Random Integers] ~ 135 cycles/int + 3,647,551 randoms generated [System.Random Bools] ~ 26.49 cycles/int + 4,296,919 randoms generated [System.Random Chars] ~ 22.48 cycles/int + + Next timing range-restricted System.Random.randomR: + 4,307,214 randoms generated [System.Random Ints] ~ 22.43 cycles/int + 4,068,982 randoms generated [System.Random Word16s] ~ 23.74 cycles/int + 2,059,264 randoms generated [System.Random Floats] ~ 46.92 cycles/int + 1,960,359 randoms generated [System.Random CFloats] ~ 49.28 cycles/int + 678,978 randoms generated [System.Random Doubles] ~ 142 cycles/int + 2,009,665 randoms generated [System.Random CDoubles] ~ 48.07 cycles/int + 4,296,452 randoms generated [System.Random Integers] ~ 22.49 cycles/int + 3,689,999 randoms generated [System.Random Bools] ~ 26.18 cycles/int + 4,367,577 randoms generated [System.Random Chars] ~ 22.12 cycles/int + 6,650 randoms generated [System.Random BIG Integers] ~ 14,528 cycles/int + diff --git a/README.md b/README.md index 0adfcdd..325f8db 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,12 @@ The Haskell Standard Library -- Random Number Generation ======================================================== -This core library is shipped with the Glasgow Haskell Compiler and +This core library is (was) shipped with the Glasgow Haskell Compiler and provides a basic interface for (splittable) random number generators. The API documentation can be found here: http://www.haskell.org/ghc/docs/latest/html/libraries/random/System-Random.html + +A module supplying this interface is required for Haskell 98. + diff --git a/System/Random.hs b/System/Random.hs index 052f568..c60d18a 100644 --- a/System/Random.hs +++ b/System/Random.hs @@ -355,11 +355,11 @@ instance Random Bool where random g = randomR (minBound,maxBound) g {-# INLINE randomRFloating #-} -randomRFloating :: (Num a, Ord a, Random a, RandomGen g) => (a, a) -> g -> (a, g) +randomRFloating :: (Fractional a, Num a, Ord a, Random a, RandomGen g) => (a, a) -> g -> (a, g) randomRFloating (l,h) g | l>h = randomRFloating (h,l) g | otherwise = let (coef,g') = random g in - (l + coef * (h-l), g') + (2.0 * (0.5*l + coef * (0.5*h - 0.5*l)), g') -- avoid overflow instance Random Double where randomR = randomRFloating @@ -445,8 +445,8 @@ randomIvalDouble (l,h) fromDouble rng (x, rng') -> let scaled_x = - fromDouble ((l+h)/2) + - fromDouble ((h-l) / realToFrac int32Count) * + fromDouble (0.5*l + 0.5*h) + -- previously (l+h)/2, overflowed + fromDouble ((0.5*h - 0.5*l) / (0.5 * realToFrac int32Count)) * -- avoid overflow fromIntegral (x::Int32) in (scaled_x, rng') diff --git a/random.cabal b/random.cabal index 7e44145..9c7b63f 100644 --- a/random.cabal +++ b/random.cabal @@ -1,7 +1,8 @@ name: random -version: 1.0.1.0 +version: 1.0.1.1 -- 1.0.1.0 -- bump for bug fixes, but no SplittableGen yet +-- 1.0.1.1 -- bump for overflow bug fixes license: BSD3 license-file: LICENSE @@ -10,7 +11,9 @@ bug-reports: http://hackage.haskell.org/trac/ghc/newticket?component=libraries/r synopsis: random number library category: System description: - This package provides a random number library. + This package provides a basic random number generation + library, including the ability to split random number + generators. build-type: Simple Cabal-Version: >= 1.6 diff --git a/tests/Makefile b/tests/Makefile index 6a0abcf..39c7149 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,3 +5,10 @@ TOP=../../../testsuite include $(TOP)/mk/boilerplate.mk include $(TOP)/mk/test.mk + + +# Build tests locally without the central GHC testing infrastructure: +local: + ghc --make rangeTest.hs + ghc --make random1283.hs + _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
