Commits

Bryan O'Sullivan committed 8dbb242

Make the ReadNumbers benchmark a little more usable.

  • Participants
  • Parent commits 1d320d0

Comments (0)

Files changed (1)

File tests/benchmarks/ReadNumbers.hs

 import Debug.Trace
 import Control.Monad
 import Data.List
-import qualified Data.Text.Lazy.Read as T
-import qualified Data.Text.Lazy.IO as T
-import qualified Data.Text.Lazy as T
+import qualified Data.Text.Read as T
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
+import qualified Data.ByteString.Char8 as B
 import System.Environment
 
 dec = T.signed T.decimal :: T.Reader Int
 
 double = T.double :: T.Reader Double
 
-def = double
+rational = T.rational :: T.Reader Double
 
-read1 :: Num a => T.Reader a -> T.Text -> a
-read1 reader = foldl' go 0 . T.lines
+read1 :: (Ord a, Num a) => T.Reader a -> T.Text -> a
+read1 reader = foldl' go 1000000 . T.lines
   where go z t = case reader t of
                    Left err    -> error err
-                   Right (n,_) -> n
+                   Right (n,_) -> min n z
     
 --paranoid :: T.Text -> [(Double)]
 paranoid = foldr go [] . T.lines
 
 main = do
   args <- getArgs
-  (print . read2 def) =<< T.getContents
+  t <- T.decodeUtf8 `fmap` B.getContents
+  case args of
+    ["dec"] -> print . read1 dec $ t
+    ["hex"] -> print . read1 hex $ t
+    ["double"] -> print . read1 double $ t
+    ["rational"] -> print . read1 rational $ t
   --mapM_ print =<< paranoid `fmap` T.getContents