helpreplacing liblzf with FastLZ


It is possible to use FastLZ as a drop-in replacement for Marc Lehmann's LibLZF.

The following graph shows the performance comparison [1,2,3] (shorter is better). The test data are the Canterbury Corpus (2.68 MB) and Silesia Corpus (96.2 MB)

To decompress data block which is previously compressed using liblzf, use function fastlz_decompress as usual. This function can automatically detect the correct format and decompress the data properly.

For example, the following code:

lzf_decompress(inbuf, length, outbuf, maxout);

can be changed to:

fastlz_decompress(inbuf, length, outbuf, maxout);

To compress data into compressed block which should be also decompressible using lzf_decompress from liblzf, use the function fastlz_compress_level and pass level equals to 1. lzf_decompress should not have problem decompressing the result.

As an example, the following code:

compressed_size = lzf_compress(data, length, output, outsize);

can be changed to:

compressed_size = fastlz_compress_level(1, data, length, output);

Please note that size of the output buffer is not passed to fastlz_compress_level. Simply allocate larger enough output buffer, at least 5% larger than the input buffer (in case the data is not compressible).


[1] Time was measured using high-resolution timer over several runs, disk I/O is excluded. Test was performed on a system with Intel Core Duo 1.8 GHz processor, 1 GB RAM running SUSE 10.2. Test program (for both FastLZ and LZF) was compiled with GCC 4.1.2 set to generate the fastest code.

[2] For the test, LZF version 3.1 (released 30-Nov-2007) was used. Default mode (ULTRA_FAST) was selected.

[3] For the test, FastLZ development version (revision 12 in the subversion repository) was used.