@@ -94,50 +94,54 @@ smallIntegerData = map fromIntegral intData
9494largeIntegerData :: [Integer ]
9595largeIntegerData = map (* (10 ^ (100 :: Integer ))) smallIntegerData
9696
97- {-# NOINLINE floatPosData #-}
98- floatPosData :: [Float ]
99- floatPosData = map evenlyDistribute [1 .. nRepl]
97+ {-# NOINLINE floatSubnormalData #-}
98+ floatSubnormalData :: [Float ]
99+ floatSubnormalData = assert (increment > 0 ) $ map evenlyDistribute [1 .. nRepl]
100100 where
101- evenlyDistribute :: Int -> Float
102101 evenlyDistribute x = castWord32ToFloat $ increment * fromIntegral x
103- increment = castFloatToWord32 maxFinite `div` fromIntegral nRepl
102+ increment = castFloatToWord32 maxSubnormal `div` fromIntegral nRepl
103+ maxSubnormal = predIEEE minNormal
104104
105- {-# NOINLINE floatNegData #-}
106- floatNegData :: [Float ]
107- floatNegData = map negate floatPosData
105+ {-# NOINLINE floatNormalData #-}
106+ floatNormalData :: [Float ]
107+ floatNormalData = assert (increment > 0 ) $ map evenlyDistribute [0 .. nRepl]
108+ where
109+ evenlyDistribute x = castWord32ToFloat $ increment * fromIntegral x + minimum
110+ increment = (maximum - minimum ) `div` fromIntegral nRepl
111+ minimum = castFloatToWord32 minNormal
112+ maximum = castFloatToWord32 maxFinite
108113
109114{-# NOINLINE floatSpecials #-}
110115floatSpecials :: [Float ]
111116floatSpecials = take nRepl $ cycle specials
112117 where
113118 specials = [nan, infinity, negate infinity, 0 - 0 ]
114119
115- {-# NOINLINE doublePosData #-}
116- doublePosData :: [Double ]
117- doublePosData = map evenlyDistribute [1 .. nRepl]
120+ {-# NOINLINE doubleSubnormalData #-}
121+ doubleSubnormalData :: [Double ]
122+ doubleSubnormalData = assert (increment > 0 ) $ map evenlyDistribute [1 .. nRepl]
118123 where
119- evenlyDistribute :: Int -> Double
120124 evenlyDistribute x = castWord64ToDouble $ increment * fromIntegral x
121- increment = (maximum - minimum ) `div` fromIntegral nRepl
122- minimum = castDoubleToWord64 $ succIEEE $ 2 ^ 53
123- maximum = castDoubleToWord64 maxFinite
124-
125- {-# NOINLINE doubleNegData #-}
126- doubleNegData :: [Double ]
127- doubleNegData = map negate doublePosData
125+ increment = castDoubleToWord64 maxSubnormal `div` fromIntegral nRepl
126+ maxSubnormal = predIEEE minNormal
128127
129- {-# NOINLINE doublePosSmallData #-}
130- doublePosSmallData :: [Double ]
131- doublePosSmallData = map evenlyDistribute [1 .. nRepl]
128+ {-# NOINLINE doubleSmallData #-}
129+ doubleSmallData :: [Double ]
130+ doubleSmallData = assert (increment > 0 ) $ map evenlyDistribute [1 .. nRepl]
132131 where
133- evenlyDistribute = assert (increment > 0 ) $ \ x -> castWord64ToDouble $ increment * fromIntegral x + minimum
132+ evenlyDistribute x = castWord64ToDouble $ increment * fromIntegral x + minimum
134133 increment = (maximum - minimum ) `div` fromIntegral nRepl
135134 minimum = castDoubleToWord64 1.0
136135 maximum = castDoubleToWord64 $ 2 ^ 53
137136
138- {-# NOINLINE doubleNegSmallData #-}
139- doubleNegSmallData :: [Double ]
140- doubleNegSmallData = map negate doublePosSmallData
137+ {-# NOINLINE doubleBigData #-}
138+ doubleBigData :: [Double ]
139+ doubleBigData = assert (increment > 0 ) $ map evenlyDistribute [1 .. nRepl]
140+ where
141+ evenlyDistribute x = castWord64ToDouble $ increment * fromIntegral x + minimum
142+ increment = (maximum - minimum ) `div` fromIntegral nRepl
143+ minimum = castDoubleToWord64 $ 2 ^ 53
144+ maximum = castDoubleToWord64 maxFinite
141145
142146{-# NOINLINE doubleSpecials #-}
143147doubleSpecials :: [Double ]
@@ -347,69 +351,11 @@ main = do
347351 , benchB " foldMap integerDec (small)" smallIntegerData $ foldMap integerDec
348352 , benchB " foldMap integerDec (large)" largeIntegerData $ foldMap integerDec
349353 , bgroup " RealFloat"
350- [ bgroup " FGeneric"
351- [ bgroup " Positive"
352- [ benchB " Float" floatPosData $ foldMap (formatFloat generic)
353- , benchB " Double" doublePosData $ foldMap (formatDouble generic)
354- , benchB " DoubleSmall" doublePosSmallData $ foldMap (formatDouble generic)
355- ]
356- , bgroup " Negative"
357- [ benchB " Float" floatNegData $ foldMap (formatFloat generic)
358- , benchB " Double" doubleNegData $ foldMap (formatDouble generic)
359- , benchB " DoubleSmall" doubleNegSmallData $ foldMap (formatDouble generic)
360- ]
361- , bgroup " Special"
362- [ benchB " Float Average" floatSpecials $ foldMap (formatFloat generic)
363- , benchB " Double Average" doubleSpecials $ foldMap (formatDouble generic)
364- ]
365- ]
366- , bgroup " FScientific"
367- [ bgroup " Positive"
368- [ benchB " Float" floatPosData $ foldMap (formatFloat scientific)
369- , benchB " Double" doublePosData $ foldMap (formatDouble scientific)
370- , benchB " DoubleSmall" doublePosSmallData $ foldMap (formatDouble scientific)
371- ]
372- , bgroup " Negative"
373- [ benchB " Float" floatNegData $ foldMap (formatFloat scientific)
374- , benchB " Double" doubleNegData $ foldMap (formatDouble scientific)
375- , benchB " DoubleSmall" doubleNegSmallData $ foldMap (formatDouble scientific)
376- ]
377- , bgroup " Special"
378- [ benchB " Float Average" floatSpecials $ foldMap (formatFloat scientific)
379- , benchB " Double Average" doubleSpecials $ foldMap (formatDouble scientific)
380- ]
381- ]
354+ [ bgroup " FGeneric" $ subAndNormalBench generic
355+ , bgroup " FScientific" $ subAndNormalBench scientific
382356 , bgroup " FStandard"
383- [ bgroup " Positive"
384- [ bgroup " default precision"
385- [ benchB " Float" floatPosData $ foldMap (formatFloat standardDefaultPrecision)
386- , benchB " Double" doublePosData $ foldMap (formatDouble standardDefaultPrecision)
387- , benchB " DoubleSmall" doublePosSmallData $ foldMap (formatDouble standardDefaultPrecision)
388- ]
389- , bgroup " precision"
390- [ benchB " Float-Precision-1" floatPosData $ foldMap (formatFloat (standard 1 ))
391- , benchB " Double-Precision-1" doublePosData $ foldMap (formatDouble (standard 1 ))
392- , benchB " DoubleSmall-Precision-1" doublePosSmallData $ foldMap (formatDouble (standard 1 ))
393- , benchB " Float-Precision-6" floatPosData $ foldMap (formatFloat (standard 6 ))
394- , benchB " Double-Precision-6" doublePosData $ foldMap (formatDouble (standard 6 ))
395- , benchB " DoubleSmall-Precision-6" doublePosSmallData $ foldMap (formatDouble (standard 6 ))
396- ]
397- ]
398- , bgroup " Negative"
399- [ bgroup " default precision"
400- [ benchB " Float" floatNegData $ foldMap (formatFloat standardDefaultPrecision)
401- , benchB " Double" doubleNegData $ foldMap (formatDouble standardDefaultPrecision)
402- , benchB " DoubleSmall" doubleNegSmallData $ foldMap (formatDouble standardDefaultPrecision)
403- ]
404- , bgroup " precision"
405- [ benchB " Float-Precision-1" floatNegData $ foldMap (formatFloat (standard 1 ))
406- , benchB " Double-Precision-1" doubleNegData $ foldMap (formatDouble (standard 1 ))
407- , benchB " DoubleSmall-Precision-1" doubleNegSmallData $ foldMap (formatDouble (standard 1 ))
408- , benchB " Float-Precision-6" floatNegData $ foldMap (formatFloat (standard 6 ))
409- , benchB " Double-Precision-6" doubleNegData $ foldMap (formatDouble (standard 6 ))
410- , benchB " DoubleSmall-Precision-6" doubleNegSmallData $ foldMap (formatDouble (standard 6 ))
411- ]
412- ]
357+ [ bgroup " Positive" $ fixedPrecision id id
358+ , bgroup " Negative" $ fixedPrecision negate negate
413359 , bgroup " Special"
414360 [ benchB " Float Average" floatSpecials $ foldMap (formatFloat standardDefaultPrecision)
415361 , benchB " Double Average" doubleSpecials $ foldMap (formatDouble standardDefaultPrecision)
@@ -625,3 +571,44 @@ main = do
625571 , benchReadInt
626572 , benchShort
627573 ]
574+
575+ subAndNormalBench format =
576+ [ bgroup " Positive" $ benchs id id
577+ , bgroup " Negative" $ benchs negate negate
578+ , bgroup " Special"
579+ [ benchB " Float Average" floatSpecials $ foldMap (formatFloat format)
580+ , benchB " Double Average" doubleSpecials $ foldMap (formatDouble format)
581+ ]
582+ ]
583+ where
584+ benchs f d =
585+ [ bgroup " Float"
586+ [ benchB " Subnormal" (map f floatSubnormalData) $ foldMap $ formatFloat format
587+ , benchB " Normal" (map f floatNormalData) $ foldMap $ formatFloat format
588+ ]
589+ , bgroup " Double"
590+ [ benchB " Subnormal" (map d doubleSubnormalData) $ foldMap $ formatDouble format
591+ , benchB " Small" (map d doubleSmallData) $ foldMap $ formatDouble format
592+ , benchB " Big" (map d doubleBigData) $ foldMap $ formatDouble format
593+ ]
594+ ]
595+
596+ fixedPrecision f d =
597+ [ bgroup " default precision"
598+ [ bgroup " Float"
599+ [ benchB " Subnormal" (map f floatSubnormalData) $ foldMap $ formatFloat standardDefaultPrecision
600+ , benchB " Normal" (map f floatNormalData) $ foldMap $ formatFloat standardDefaultPrecision
601+ ]
602+ , bgroup " Double"
603+ [ benchB " Subnormal" (map d doubleSubnormalData) $ foldMap $ formatDouble standardDefaultPrecision
604+ , benchB " Small" (map d doubleSmallData) $ foldMap $ formatDouble standardDefaultPrecision
605+ , benchB " Big" (map d doubleBigData) $ foldMap $ formatDouble standardDefaultPrecision
606+ ]
607+ ]
608+ , bgroup " precision"
609+ [ benchB " Float-Precision-1" (map f floatNormalData) $ foldMap $ formatFloat $ standard 1
610+ , benchB " Double-Precision-1" (map d doubleSmallData) $ foldMap $ formatDouble $ standard 1
611+ , benchB " Float-Precision-6" (map f floatNormalData) $ foldMap $ formatFloat $ standard 6
612+ , benchB " Double-Precision-6" (map d doubleSmallData) $ foldMap $ formatDouble $ standard 6
613+ ]
614+ ]
0 commit comments