Some implementations of compression algorithms for educational purposes.
Benchmarks:
$ python3 -m benchmarks.run_benchmark
Tests:
# run lzw tests
$ python3 -m unittest tests/test_lzw.py
# run huffman tests
$ python3 -m unittest tests/test_huffman.py
The algorithms implemented are Lempel–Ziv–Welch and Huffman. Here's a comparison between them using some works of literature or random big texts.
Work of art | Original size | LZW size | Huffman size | LZW % reduction | Huffman % reduction |
---|---|---|---|---|---|
Hamlet | 191726 bytes | 119197 bytes | 105405 bytes | 37.83% | 45.02% |
Lorem Ipsum | 9634 bytes | 7842 bytes | 5414 bytes | 18.60% | 43.80% |
Dom Casmurro | 383499 bytes | Not supported | 105405 bytes | Not supported | 44.87% |