def test_huffman(): camzip.camzip("huffman", "hamlet.txt") return
def test_shanon_fano(): camzip.camzip("shannon_fano", "hamlet.txt") return
import os import time filename = "hamlet_10.txt" #filename = "hamlet_extended.txt" print("Original file size:", os.path.getsize(filename)) start_time = time.time() method = "arithmetic" camzip(method, filename) print("Encoded") print("Arith: --- %s seconds ---" % (time.time() - start_time)) print("File size:", os.path.getsize(filename + '.cz' + method[0])) start2_time = time.time() method = "context" camzip(method, filename) print("Context: --- %s seconds ---" % (time.time() - start2_time)) print("File size:", os.path.getsize(filename + '.cz' + method[0]))
def test_arithmetic(): camzip.camzip("arithmetic", "hamlet.txt") return
from camzip import camzip import matplotlib.pyplot as plt cz = camzip() hm = [] sf = [] x = [] for i in range(1, 10): hm.append(cz.zip('huffman', 'hamlet.txt', i, True)) sf.append(cz.zip('shannon_fano', 'hamlet.txt', i, True)) x.append(i) plt.plot(x, hm, label='Huffman') plt.plot(x, sf, label='Shannon-Fano') plt.xlabel('N') plt.ylabel('Compression Ratio') plt.legend() plt.grid() plt.show()