Permalink
Browse files

Added tests and benchmarks for BIG Integers.

  • Loading branch information...
1 parent f2a3d60 commit 327401e49c6b8b1e9f0dbec87f4a802fc33eb7e3 @rrnewton rrnewton committed Jun 28, 2011
Showing with 21 additions and 7 deletions.
  1. +4 −7 Benchmark/SimpleRNGBench.hs
  2. +13 −0 DEVLOG.md
  3. +2 −0 tests/rangeTest.hs
  4. +2 −0 tests/rangeTest.stdout
@@ -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():"
View
@@ -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
+
View
@@ -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))
View
@@ -1,5 +1,7 @@
Int: Passed
Integer: Passed
+Integer Rbig: Passed
+Integer RbigPos: Passed
Int8: Passed
Int16: Passed
Int32: Passed

0 comments on commit 327401e

Please sign in to comment.