Install necessary software packages

  • Make sure python3 is available when python is run.

            sudo apt install python-is-python3 -y

Detailed Steps

The previous section explained how to build the Cloudflare zlib which includes the use of crc32 instructions to improve performance on data compression.

Use a Python example and measure the performance difference with zlib-cloudflare.

Use a text editor to copy and save the code below in a file named


            import gzip

size = 16384

with open('largefile', 'rb') as f_in:
    with'largefile.gz', 'wb') as f_out:
        while (data :=


Create a large file to compress

The above Python code will read a file named largefile and write a compressed version as largefile.gz

To create the input file, use the dd command.


            dd if=/dev/zero of=largefile count=1M bs=1024

Run the example using the default zlib

Run with the default zlib and time the execution.


            time python ./

Make a note of how many seconds the program took.

Run the example again with zlib-cloudflare

This time, use LD_PRELOAD to change to zlib-cloudflare instead and check the performance difference.

Adjust the path to as needed.


            time LD_PRELOAD=/usr/local/lib/ python ./

Notice the time saved using zlib-cloudflare.

The next section introduces how to use Linux perf to profile applications and look for zlib activity.