Compressing Data
271
the task. In case time is your concern, most algorithms let you trade some com-
pression ratio for speedier compression and decompression. In the preceding
example for the Sherlock Holmes text, the compression ratio is 226824 / 594941,
that is, about 0.381. The
compress
method found in the example has a second
optional parameter,
level
, which controls the level of compression. Changing
this parameter controls the ratio between the time to perform the task and the
amount of compression achieved.
Choosing your encoding wisely
The example in the preceding section shows what happens when you apply the
ZIP algorithm to random text. The results help you understand why compression
works. Boiling down all the available compression algorithms, you discover four
main reasons:
Do'stlaringiz bilan baham: |