Bryan O'Sullivan avatar Bryan O'Sullivan committed 9d0e1f9

Measure compression ratio

Comments (0)

Files changed (1)

   evaluate $ if action == Compress then c 0 bs else d 0 bs
   time <- (fromRational . toRational . flip diffUTCTime start) `fmap`
           getCurrentTime
-  return $ fromIntegral (B.length bs) * fromIntegral count / (time * 1048576.0)
+  return (fromIntegral (B.length bs) * fromIntegral count / (time * 1048576.0),
+          (B.length (S.compress bs0) * 100) `div` B.length bs0)
 
 gzip Command{..} f = do
   bs0 <- L.readFile f
   evaluate $ if action == Compress then c 0 bs else d 0 bs
   time <- (fromRational . toRational . flip diffUTCTime start) `fmap`
           getCurrentTime
-  return $ fromIntegral len * fromIntegral count / (time * 1048576.0)
+  return (fromIntegral len * fromIntegral count / (time * 1048576.0),
+          fromIntegral $ (L.length (compress bs0) * 100) `div` L.length bs0)
 
 main = do
   c@Command{..} <- cmdArgs command
   forM_ files $ \f -> do
-    mbSec <- (if codec == Snappy then snappy else gzip) c f
+    (mbSec, ratio) <- (if codec == Snappy then snappy else gzip) c f
     putStrLn $ show codec ++ " " ++ show action ++ " " ++
-               show f ++ ": " ++ show (round mbSec) ++ " MB/sec"
+               show f ++ ": " ++ show (round mbSec) ++ " MB/sec, " ++
+               show (100 - ratio) ++ "% smaller"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.