Example #1
0
def main():
    txt = open('README').read()
    code = huffCode(freq_string(txt))

    sample = 2000 * txt

    a = bitarray()
    a.encode(code, sample)

    # Time the decode function above
    start_time = time.time()
    res = decode(code, a)
    Py_time = time.time() - start_time
    assert ''.join(res) == sample
    print('Py_time: %.6f sec' % Py_time)

    # Time the decode method which is implemented in C
    start_time = time.time()
    res = a.decode(code)
    C_time = time.time() - start_time
    assert ''.join(res) == sample
    print('C_time: %.6f sec' % C_time)

    print('Ratio: %f' % (Py_time / C_time))
Example #2
0
def main():
    txt = open('README').read()
    code = huffCode(freq_string(txt))

    sample = 2000 * txt

    a = bitarray()
    a.encode(code, sample)

    # Time the decode function above
    start_time = time.time()
    res = decode(code, a)
    Py_time = time.time() - start_time
    assert ''.join(res) == sample
    print('Py_time: %.6f sec' % Py_time)

    # Time the decode method which is implemented in C
    start_time = time.time()
    res = a.decode(code)
    C_time = time.time() - start_time
    assert ''.join(res) == sample
    print('C_time: %.6f sec' % C_time)

    print('Ratio: %f' % (Py_time / C_time))
Example #3
0
    res = []
    it = iter(bitsequence)
    while True:
        r = traverse(it, tree)
        if r is False:
            break
        else:
            if r == []:
                raise ValueError("prefix code does not match data")
            res.append(r)

    return res


txt = open('README').read()
code = huffCode(freq_string(txt))

sample = 1000*txt

a = bitarray()
a.encode(code, sample)

# Time the decode function above
start_time = time.time()
res = decode(code, a)
Py_time = time.time() - start_time
assert ''.join(res) == sample
print('Py_time: %.6f sec' % Py_time)

# Time the decode method which is implemented in C
start_time = time.time()
Example #4
0
    res = []
    it = iter(bitsequence)
    while True:
        r = traverse(it, tree)
        if r is False:
            break
        else:
            if r == []:
                raise ValueError("prefix code does not match data")
            res.append(r)

    return res


txt = open('README').read()
code = huffCode(freq_string(txt))

sample = 1000 * txt

a = bitarray()
a.encode(code, sample)

# Time the decode function above
start_time = time.time()
res = decode(code, a)
Py_time = time.time() - start_time
assert ''.join(res) == sample
print('Py_time: %.6f sec' % Py_time)

# Time the decode method which is implemented in C
start_time = time.time()