]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/zstd/README.md
DIRDEPS_BUILD: Fix after r325417.
[FreeBSD/FreeBSD.git] / contrib / zstd / README.md
1  __Zstandard__, or `zstd` as short version, is a fast lossless compression algorithm,
2  targeting real-time compression scenarios at zlib-level and better compression ratios.
3
4 It is provided as an open-source BSD-licensed **C** library,
5 and a command line utility producing and decoding `.zst` and `.gz` files.
6 For other programming languages,
7 you can consult a list of known ports on [Zstandard homepage](http://www.zstd.net/#other-languages).
8
9 | dev branch status |
10 |-------------------|
11 | [![Build Status][travisDevBadge]][travisLink]   [![Build status][AppveyorDevBadge]][AppveyorLink]   [![Build status][CircleDevBadge]][CircleLink]
12
13 [travisDevBadge]: https://travis-ci.org/facebook/zstd.svg?branch=dev "Continuous Integration test suite"
14 [travisLink]: https://travis-ci.org/facebook/zstd
15 [AppveyorDevBadge]: https://ci.appveyor.com/api/projects/status/xt38wbdxjk5mrbem/branch/dev?svg=true "Windows test suite"
16 [AppveyorLink]: https://ci.appveyor.com/project/YannCollet/zstd-p0yf0
17 [CircleDevBadge]: https://circleci.com/gh/facebook/zstd/tree/dev.svg?style=shield "Short test suite"
18 [CircleLink]: https://circleci.com/gh/facebook/zstd
19
20
21 As a reference, several fast compression algorithms were tested and compared
22 on a server running Linux Debian (`Linux version 4.8.0-1-amd64`),
23 with a Core i7-6700K CPU @ 4.0GHz,
24 using [lzbench], an open-source in-memory benchmark by @inikep
25 compiled with GCC 6.3.0,
26 on the [Silesia compression corpus].
27
28 [lzbench]: https://github.com/inikep/lzbench
29 [Silesia compression corpus]: http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia
30
31 | Compressor name         | Ratio | Compression| Decompress.|
32 | ---------------         | ------| -----------| ---------- |
33 | **zstd 1.1.3 -1**       | 2.877 |   430 MB/s |  1110 MB/s |
34 | zlib 1.2.8 -1           | 2.743 |   110 MB/s |   400 MB/s |
35 | brotli 0.5.2 -0         | 2.708 |   400 MB/s |   430 MB/s |
36 | quicklz 1.5.0 -1        | 2.238 |   550 MB/s |   710 MB/s |
37 | lzo1x 2.09 -1           | 2.108 |   650 MB/s |   830 MB/s |
38 | lz4 1.7.5               | 2.101 |   720 MB/s |  3600 MB/s |
39 | snappy 1.1.3            | 2.091 |   500 MB/s |  1650 MB/s |
40 | lzf 3.6 -1              | 2.077 |   400 MB/s |   860 MB/s |
41
42 [zlib]:http://www.zlib.net/
43 [LZ4]: http://www.lz4.org/
44
45 Zstd can also offer stronger compression ratios at the cost of compression speed.
46 Speed vs Compression trade-off is configurable by small increments. Decompression speed is preserved and remains roughly the same at all settings, a property shared by most LZ compression algorithms, such as [zlib] or lzma.
47
48 The following tests were run
49 on a server running Linux Debian (`Linux version 4.8.0-1-amd64`)
50 with a Core i7-6700K CPU @ 4.0GHz,
51 using [lzbench], an open-source in-memory benchmark by @inikep
52 compiled with GCC 6.3.0,
53 on the [Silesia compression corpus].
54
55 Compression Speed vs Ratio | Decompression Speed
56 ---------------------------|--------------------
57 ![Compression Speed vs Ratio](doc/images/Cspeed4.png "Compression Speed vs Ratio") | ![Decompression Speed](doc/images/Dspeed4.png "Decompression Speed")
58
59 Several algorithms can produce higher compression ratios, but at slower speeds, falling outside of the graph.
60 For a larger picture including very slow modes, [click on this link](doc/images/DCspeed5.png) .
61
62
63 ### The case for Small Data compression
64
65 Previous charts provide results applicable to typical file and stream scenarios (several MB). Small data comes with different perspectives.
66
67 The smaller the amount of data to compress, the more difficult it is to compress. This problem is common to all compression algorithms, and reason is, compression algorithms learn from past data how to compress future data. But at the beginning of a new data set, there is no "past" to build upon.
68
69 To solve this situation, Zstd offers a __training mode__, which can be used to tune the algorithm for a selected type of data.
70 Training Zstandard is achieved by providing it with a few samples (one file per sample). The result of this training is stored in a file called "dictionary", which must be loaded before compression and decompression.
71 Using this dictionary, the compression ratio achievable on small data improves dramatically.
72
73 The following example uses the `github-users` [sample set](https://github.com/facebook/zstd/releases/tag/v1.1.3), created from [github public API](https://developer.github.com/v3/users/#get-all-users).
74 It consists of roughly 10K records weighing about 1KB each.
75
76 Compression Ratio | Compression Speed | Decompression Speed
77 ------------------|-------------------|--------------------
78 ![Compression Ratio](doc/images/dict-cr.png "Compression Ratio") | ![Compression Speed](doc/images/dict-cs.png "Compression Speed") | ![Decompression Speed](doc/images/dict-ds.png "Decompression Speed")
79
80
81 These compression gains are achieved while simultaneously providing _faster_ compression and decompression speeds.
82
83 Training works if there is some correlation in a family of small data samples. The more data-specific a dictionary is, the more efficient it is (there is no _universal dictionary_).
84 Hence, deploying one dictionary per type of data will provide the greatest benefits.
85 Dictionary gains are mostly effective in the first few KB. Then, the compression algorithm will gradually use previously decoded content to better compress the rest of the file.
86
87 #### Dictionary compression How To :
88
89 1) Create the dictionary
90
91 `zstd --train FullPathToTrainingSet/* -o dictionaryName`
92
93 2) Compress with dictionary
94
95 `zstd -D dictionaryName FILE`
96
97 3) Decompress with dictionary
98
99 `zstd -D dictionaryName --decompress FILE.zst`
100
101
102 ### Build
103
104 Once you have the repository cloned, there are multiple ways provided to build Zstandard.
105
106 #### Makefile
107
108 If your system is compatible with a standard `make` (or `gmake`) binary generator,
109 you can simply run it at the root directory.
110 It will generate `zstd` within root directory.
111
112 Other available options include :
113 - `make install` : create and install zstd binary, library and man page
114 - `make test` : create and run `zstd` and test tools on local platform
115
116 #### cmake
117
118 A `cmake` project generator is provided within `build/cmake`.
119 It can generate Makefiles or other build scripts
120 to create `zstd` binary, and `libzstd` dynamic and static libraries.
121
122 #### Meson
123
124 A Meson project is provided within `contrib/meson`.
125
126 #### Visual Studio (Windows)
127
128 Going into `build` directory, you will find additional possibilities :
129 - Projects for Visual Studio 2005, 2008 and 2010
130   + VS2010 project is compatible with VS2012, VS2013 and VS2015
131 - Automated build scripts for Visual compiler by @KrzysFR , in `build/VS_scripts`,
132   which will build `zstd` cli and `libzstd` library without any need to open Visual Studio solution.
133
134
135 ### Status
136
137 Zstandard is currently deployed within Facebook. It is used continuously to compress large amounts of data in multiple formats and use cases.
138 Zstandard is considered safe for production environments.
139
140 ### License
141
142 Zstandard is dual-licensed under [BSD](LICENSE) and [GPLv2](COPYING).
143
144 ### Contributing
145
146 The "dev" branch is the one where all contributions will be merged before reaching "master".
147 If you plan to propose a patch, please commit into the "dev" branch or its own feature branch.
148 Direct commit to "master" are not permitted.
149 For more information, please read [CONTRIBUTING](CONTRIBUTING.md).
150
151 ### Miscellaneous
152
153 Zstd entropy stage is provided by [Huff0 and FSE, from Finite State Entropy library](https://github.com/Cyan4973/FiniteStateEntropy).