From 37e28f8c0e946f5df79d0c307e93bb27c078a7fe Mon Sep 17 00:00:00 2001 From: Jack Wines Date: Mon, 15 Apr 2024 01:54:33 -0700 Subject: [PATCH] main shows compression ratios again README also updated to show compression ratios. --- README.md | 2 ++ src/Main.hs | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7bfdd5f..b2d1930 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ Compresses files using [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding). Please note that decompression isn't fully implemented yet. It is however implemented to the point where we know compression works correctly. +On [The Great Gatsby in plain text](https://www.gutenberg.org/cache/epub/64317/pg64317.txt) on project Gutenberg, it achieves a 0.526 compression ratio when using a word size of two bytes. On an arbitrary RAW image, it peaks at .622 with a 32 bit word size and .645 with a 16 bit one. + To run with [Nix](nixos.org): ``` sh nix run ".#" --experimental-features "nix-command flakes" -- myFile diff --git a/src/Main.hs b/src/Main.hs index 9b20368..c2789af 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -140,9 +140,10 @@ main :: IO () main = do [filePath] <- SE.getArgs f <- BS.readFile filePath - -- TIO.putStrLn "compression ratios:" + TIO.putStrLn "does decompress . compress == id ?" print . ("Word64",) . testCompression (D.Proxy :: D.Proxy Word16) $ f - -- print . ("Word64",) . compressionRatioFor (D.Proxy :: D.Proxy Word64) $ f - -- print . ("Word32",) . compressionRatioFor (D.Proxy :: D.Proxy Word32) $ f - -- print . ("Word16",) . compressionRatioFor (D.Proxy :: D.Proxy Word16) $ f - -- print . ("Word8",) . compressionRatioFor (D.Proxy :: D.Proxy Word8) $ f + TIO.putStrLn "compression ratios:" + print . ("Word64",) . compressionRatioFor (D.Proxy :: D.Proxy Word64) $ f + print . ("Word32",) . compressionRatioFor (D.Proxy :: D.Proxy Word32) $ f + print . ("Word16",) . compressionRatioFor (D.Proxy :: D.Proxy Word16) $ f + print . ("Word8",) . compressionRatioFor (D.Proxy :: D.Proxy Word8) $ f