Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Port of LZ4 Compression algorithm to C#
C# C
branch: master

This port is unmaintained and unlikely to be updated. I have personally switched to using Yann Collet’s C code via C++/CLI. For a .NET LZ4 solution try which has multiple configuration and includes LZ4HC.


Port of Yann Collet’s LZ4 algorithm to C# by Clayton Stangeland.

Original LZ4 algorithm can be found at ( it was created by Yann Collet. See license.txt for project license.


Building in Debug or Release will use the already generated C# files

LZ4Compressor.c and LZ4Decompressor.c are updated by manually comparing to the original LZ4 code and fixing any C# differences from C but leaving some of the macros to make comparing easier.

Then building in the Generated configuration will only build the LZ4SharpGenerator project which has a prebuild event that uses the MinGW gcc from CodeBlocks to generate the C# files from LZ4Compressor.c and LZ4Decompressor.c.


Compression times do not include disk I/O.

P4 = Pentium 4 2GHz 32 bit Windows XP

i5 = Intel i5 2.67 GHZ 64 bit Windows 7 running LZ4Sharp in 64 bit

LZ4Sharp = Timings for ‘webster’ from silesia corpus (

memcpy and LZ4 = Timing for file ‘webster’ in silesia corpus in m2mark.exe from (or from link to benchmark program at

gzip = GZip from the Intel compiler built as a dll and accessed from C# by PInvoke

Ratio = compressed size / decompressed size (lower is better)

Computer Type Compression (MB/s) Decompression (MB/s) Ratio (%)
P4 memcpy 217
P4 LZ4 82 304
P4 LZ4Sharp 43 150
P4 LZ4Sharp 49 181
i5 memcpy 1658
i5 LZ4 270 1184
i5 LZ4Sharp 207 758 49
i5 LZ4Sharp 267 838 47
i5 gzip 48 266 33


LZ4 C# is about 2/3 the speed of the c version. (Also, LZ4C# is slightly faster on the whole silesia corpus than on just the ‘webster’ file) LZ4 C# Compressed silesia corpus is 47% of uncompressed LZ4 C# Compressed ‘webster’ file is 49% of uncompressed

Something went wrong with that request. Please try again.