[commit: random] master: Added tests and benchmarks for BIG Integers. (327401e)
Ian Lynagh
igloo at earth.li
Fri Jul 8 18:47:41 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/random
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/327401e49c6b8b1e9f0dbec87f4a802fc33eb7e3
>---------------------------------------------------------------
commit 327401e49c6b8b1e9f0dbec87f4a802fc33eb7e3
Author: Ryan Newton <rrnewton at gmail.com>
Date: Tue Jun 28 10:07:45 2011 -0400
Added tests and benchmarks for BIG Integers.
>---------------------------------------------------------------
Benchmark/SimpleRNGBench.hs | 11 ++++-------
DEVLOG.md | 13 +++++++++++++
tests/rangeTest.hs | 2 ++
tests/rangeTest.stdout | 2 ++
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/Benchmark/SimpleRNGBench.hs b/Benchmark/SimpleRNGBench.hs
index 05cfda5..114722c 100644
--- a/Benchmark/SimpleRNGBench.hs
+++ b/Benchmark/SimpleRNGBench.hs
@@ -253,13 +253,7 @@ main = do
randCDouble = random :: RandomGen g => g -> (CDouble,g)
randInteger = random :: RandomGen g => g -> (Integer,g)
randBool = random :: RandomGen g => g -> (Bool,g)
-
- -- rangeFloat g = randomR (-100, 100::Float) g
- -- rangeCFloat g = randomR (-100, 100::CFloat) g
- -- rangeDouble g = randomR (-100, 100::Double) g
- -- rangeCDouble g = randomR (-100, 100::CDouble) g
- -- rangeInteger g = randomR (-100, 100::Integer) g
- -- rangeBool g = randomR (False, True) g
+ randChar = random :: RandomGen g => g -> (Char,g)
gen = mkStdGen 23852358661234
gamut th = do
@@ -276,6 +270,7 @@ main = do
timeit th freq "System.Random CDoubles" gen randCDouble
timeit th freq "System.Random Integers" gen randInteger
timeit th freq "System.Random Bools" gen randBool
+ timeit th freq "System.Random Chars" gen randChar
#ifdef TEST_COMPETITORS
putStrLn$ "\n Next test other RNG packages on Hackage:"
@@ -306,6 +301,8 @@ main = do
timeit th freq "System.Random CDoubles" gen (randomR (-100, 100::CDouble))
timeit th freq "System.Random Integers" gen (randomR (-100, 100::Integer))
timeit th freq "System.Random Bools" gen (randomR (False, True::Bool))
+ timeit th freq "System.Random Chars" gen (randomR ('a', 'z'))
+ timeit th freq "System.Random BIG Integers" gen (randomR (0, (2::Integer) ^ (5000::Int)))
-- when (not$ NoC `elem` opts) $ do
-- putStrLn$ " Comparison to C's rand():"
diff --git a/DEVLOG.md b/DEVLOG.md
index c56de58..ef235d1 100644
--- a/DEVLOG.md
+++ b/DEVLOG.md
@@ -90,3 +90,16 @@ After reimplementing random/Float these are the new results:
(But I still need to propagate these changes throughout all types / API calls.)
+
+[2011.06.28] Integer Generation via random and randomR
+-------------------------------------------------------
+
+Back on the master branch I notice that while randomIvalInteger does
+well for small ranges, it's advantage doesn't scale to larger ranges:
+
+ range (-100,100):
+ 5,105,290 randoms generated [System.Random Integers] ~ 653 cycles/int
+
+ range (0,2^5000):
+ 8,969 randoms generated [System.Random BIG Integers] ~ 371,848 cycles/int
+
diff --git a/tests/rangeTest.hs b/tests/rangeTest.hs
index ec95e56..88f736d 100644
--- a/tests/rangeTest.hs
+++ b/tests/rangeTest.hs
@@ -58,6 +58,8 @@ main =
do
checkBounds "Int" (intRange nb) (approxBounds random trials (undefined::Int))
checkBounds "Integer" (intRange nb) (approxBounds random trials (undefined::Integer))
+ checkBounds "Integer Rbig" (False,-(2^500), 2^500) (approxBounds (randomR (-(2^500), 2^500)) trials (undefined::Integer))
+ checkBounds "Integer RbigPos" (False,1,2^5000) (approxBounds (randomR (1,2^5000)) trials (undefined::Integer))
checkBounds "Int8" (intRange 8) (approxBounds random trials (undefined::Int8))
checkBounds "Int16" (intRange 16) (approxBounds random trials (undefined::Int16))
checkBounds "Int32" (intRange 32) (approxBounds random trials (undefined::Int32))
diff --git a/tests/rangeTest.stdout b/tests/rangeTest.stdout
index 55ccaff..f9d9479 100644
--- a/tests/rangeTest.stdout
+++ b/tests/rangeTest.stdout
@@ -1,5 +1,7 @@
Int: Passed
Integer: Passed
+Integer Rbig: Passed
+Integer RbigPos: Passed
Int8: Passed
Int16: Passed
Int32: Passed
More information about the Cvs-libraries
mailing list