Find a file
huangwenjun 418a6e233c optimize unaligned operator same as arm.
After optimze:
M_UFlat/0             193373     192048       1017 508.5MB/s  html
BM_UFlat/1            1983820    1992190        100 336.1MB/s  urls
BM_UFlat/2              49493      49842       3997 2.3GB/s  jpg
BM_UFlat/3                962        943     190476 202.2MB/s  jpg_200
BM_UFlat/4              47904      48501       4188 2.0GB/s  pdf
BM_UFlat/5             794704     796872        250 490.2MB/s  html4
BM_UFlat/6             679119     677615        294 214.0MB/s  txt1
BM_UFlat/7             589044     587666        339 203.1MB/s  txt2
BM_UFlat/8            1823009    1827697        109 222.7MB/s  txt3
BM_UFlat/9            2486760    2460940        100 186.7MB/s  txt4
BM_UFlat/10            185680     187411       1063 603.5MB/s  pb
BM_UFlat/11            741161     734259        266 239.4MB/s  gaviota
BM_UIOVec/0            491849     490687        406 199.0MB/s  html
BM_UIOVec/1           4269690    4257810        100 157.3MB/s  urls
BM_UIOVec/2             53773      54106       3682 2.1GB/s  jpg
BM_UIOVec/3              2261       2255      86580 84.6MB/s  jpg_200
BM_UIOVec/4             75054      75604       2635 1.3GB/s  pdf
BM_UValidate/0         109026     107788       1812 906.0MB/s  html
BM_UValidate/1        1247281    1245118        160 537.7MB/s  urls
BM_UValidate/2            727        720     243902 159.1GB/s  jpg
BM_UValidate/3            508        507     338983 376.2MB/s  jpg_200
BM_UValidate/4          10552      10549      18885 9.0GB/s  pdf
BM_ZFlat/0             700492     701471        284 139.2MB/s  html (22.31 %)
BM_ZFlat/1            7840690    7812500        100 85.7MB/s  urls (47.78 %)
BM_ZFlat/2              60742      61091       3261 1.9GB/s  jpg (99.95 %)
BM_ZFlat/3               2971       2947      64935 64.7MB/s  jpg_200 (73.00 %)
BM_ZFlat/4             107158     105860       1845 922.5MB/s  pdf (83.30 %)
BM_ZFlat/5            2808390    2812500        100 138.9MB/s  html4 (22.52 %)
BM_ZFlat/6            2405510    2382810        100 60.9MB/s  txt1 (57.88 %)
BM_ZFlat/7            2084040    2070310        100 57.7MB/s  txt2 (61.91 %)
BM_ZFlat/8            6396990    6406250        100 63.5MB/s  txt3 (54.99 %)
BM_ZFlat/9            8521580    8515620        100 54.0MB/s  txt4 (66.26 %)
BM_ZFlat/10            665106     664063        300 170.3MB/s  pb (19.68 %)
BM_ZFlat/11           2192610    2187500        100 80.4MB/s  gaviota (37.72 %)

Before optimze:
Benchmark            Time(ns)    CPU(ns) Iterations
---------------------------------------------------
BM_UFlat/0             409250     408235        488 239.2MB/s  html
BM_UFlat/1            3779030    3750000        100 178.5MB/s  urls
BM_UFlat/2              50095      49446       3950 2.3GB/s  jpg
BM_UFlat/3               1342       1328     123456 143.5MB/s  jpg_200
BM_UFlat/4              70687      71517       2731 1.3GB/s  pdf
BM_UFlat/5            1661500    1660150        120 235.3MB/s  html4
BM_UFlat/6            1586744    1562496        125 92.8MB/s  txt1
BM_UFlat/7            1341067    1337040        149 89.3MB/s  txt2
BM_UFlat/8            4188730    4179690        100 97.4MB/s  txt3
BM_UFlat/9            5595520    5585930        100 82.3MB/s  txt4
BM_UFlat/10            369473     371677        536 304.3MB/s  pb
BM_UFlat/11           1830678    1827697        109 96.2MB/s  gaviota
BM_UIOVec/0            634178     634455        314 153.9MB/s  html
BM_UIOVec/1           5571610    5585940        100 119.9MB/s  urls
BM_UIOVec/2             54381      54610       3648 2.1GB/s  jpg
BM_UIOVec/3              2618       2587      72463 73.7MB/s  jpg_200
BM_UIOVec/4             88890      89416       2228 1.1GB/s  pdf
BM_UValidate/0         230980     227372        859 429.5MB/s  html
BM_UValidate/1        2178450    2187500        100 306.1MB/s  urls
BM_UValidate/2           1112       1101     166666 104.1GB/s  jpg
BM_UValidate/3            692        682     263157 279.3MB/s  jpg_200
BM_UValidate/4          23802      23898       8336 4.0GB/s  pdf
BM_ZFlat/0            4405980    4375000        100 22.3MB/s  html (22.31 %)
BM_ZFlat/1           52297430   52187500        100 12.8MB/s  urls (47.78 %)
BM_ZFlat/2             168751     169837       1173 691.2MB/s  jpg (99.95 %)
BM_ZFlat/3              21565      21716       8814 8.8MB/s  jpg_200 (73.00 %)
BM_ZFlat/4             706390     706446        282 138.2MB/s  pdf (83.30 %)
BM_ZFlat/5           17759550   17734370        100 22.0MB/s  html4 (22.52 %)
BM_ZFlat/6           12785910   12773440        100 11.4MB/s  txt1 (57.88 %)
BM_ZFlat/7           11020140   10976560        100 10.9MB/s  txt2 (61.91 %)
BM_ZFlat/8           34391200   34296880        100 11.9MB/s  txt3 (54.99 %)
BM_ZFlat/9           44832460   44726570        100 10.3MB/s  txt4 (66.26 %)
BM_ZFlat/10           4650820    4648440        100 24.3MB/s  pb (19.68 %)
BM_ZFlat/11          11624620   11601560        100 15.2MB/s  gaviota (37.72 %)
2018-08-20 10:38:07 +08:00
cmake C++11 guarantees <cstddef> and <cstdint>. 2018-08-16 11:36:45 -07:00
testdata
.appveyor.yml Fix Visual Studio build. 2018-08-08 22:25:14 -07:00
.travis.yml Remove GCC on OSX from the Travis CI matrix. 2018-08-16 11:36:19 -07:00
AUTHORS
CMakeLists.txt C++11 guarantees <cstddef> and <cstdint>. 2018-08-16 11:36:45 -07:00
CONTRIBUTING.md Add guidelines for opensource contributions. 2017-08-01 14:38:24 -07:00
COPYING
format_description.txt
framing_format.txt
NEWS Tag open source release 1.1.7. 2017-08-24 16:54:23 -07:00
README.md
snappy-c.cc
snappy-c.h
snappy-internal.h optimize unaligned operator same as arm. 2018-08-20 10:38:07 +08:00
snappy-sinksource.cc
snappy-sinksource.h
snappy-stubs-internal.cc
snappy-stubs-internal.h optimize unaligned operator same as arm. 2018-08-20 10:38:07 +08:00
snappy-stubs-public.h.in C++11 guarantees <cstddef> and <cstdint>. 2018-08-16 11:36:45 -07:00
snappy-test.cc
snappy-test.h C++11 guarantees <cstddef> and <cstdint>. 2018-08-16 11:36:45 -07:00
snappy.cc optimize unaligned operator same as arm. 2018-08-20 10:38:07 +08:00
snappy.h C++11 guarantees <cstddef> and <cstdint>. 2018-08-16 11:36:45 -07:00
snappy_unittest.cc Improve performance of zippy decompression to IOVecs by up to almost 50% 2018-08-07 23:41:17 -07:00

Snappy, a fast compressor/decompressor.

Introduction

Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression. For instance, compared to the fastest mode of zlib, Snappy is an order of magnitude faster for most inputs, but the resulting compressed files are anywhere from 20% to 100% bigger. (For more information, see "Performance", below.)

Snappy has the following properties:

  • Fast: Compression speeds at 250 MB/sec and beyond, with no assembler code. See "Performance" below.
  • Stable: Over the last few years, Snappy has compressed and decompressed petabytes of data in Google's production environment. The Snappy bitstream format is stable and will not change between versions.
  • Robust: The Snappy decompressor is designed not to crash in the face of corrupted or malicious input.
  • Free and open source software: Snappy is licensed under a BSD-type license. For more information, see the included COPYING file.

Snappy has previously been called "Zippy" in some Google presentations and the like.

Performance

Snappy is intended to be fast. On a single core of a Core i7 processor in 64-bit mode, it compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more. (These numbers are for the slowest inputs in our benchmark suite; others are much faster.) In our tests, Snappy usually is faster than algorithms in the same class (e.g. LZO, LZF, QuickLZ, etc.) while achieving comparable compression ratios.

Typical compression ratios (based on the benchmark suite) are about 1.5-1.7x for plain text, about 2-4x for HTML, and of course 1.0x for JPEGs, PNGs and other already-compressed data. Similar numbers for zlib in its fastest mode are 2.6-2.8x, 3-7x and 1.0x, respectively. More sophisticated algorithms are capable of achieving yet higher compression rates, although usually at the expense of speed. Of course, compression ratio will vary significantly with the input.

Although Snappy should be fairly portable, it is primarily optimized for 64-bit x86-compatible processors, and may run slower in other environments. In particular:

  • Snappy uses 64-bit operations in several places to process more data at once than would otherwise be possible.
  • Snappy assumes unaligned 32- and 64-bit loads and stores are cheap. On some platforms, these must be emulated with single-byte loads and stores, which is much slower.
  • Snappy assumes little-endian throughout, and needs to byte-swap data in several places if running on a big-endian platform.

Experience has shown that even heavily tuned code can be improved. Performance optimizations, whether for 64-bit x86 or other platforms, are of course most welcome; see "Contact", below.

Building

CMake is supported and autotools will soon be deprecated. You need CMake 3.4 or above to build:

mkdir build cd build && cmake ../ && make

Usage

Note that Snappy, both the implementation and the main interface, is written in C++. However, several third-party bindings to other languages are available; see the home page at http://google.github.io/snappy/ for more information. Also, if you want to use Snappy from C code, you can use the included C bindings in snappy-c.h.

To use Snappy from your own C++ program, include the file "snappy.h" from your calling file, and link against the compiled library.

There are many ways to call Snappy, but the simplest possible is

snappy::Compress(input.data(), input.size(), &output);

and similarly

snappy::Uncompress(input.data(), input.size(), &output);

where "input" and "output" are both instances of std::string.

There are other interfaces that are more flexible in various ways, including support for custom (non-array) input sources. See the header file for more information.

Tests and benchmarks

When you compile Snappy, snappy_unittest is compiled in addition to the library itself. You do not need it to use the compressor from your own library, but it contains several useful components for Snappy development.

First of all, it contains unit tests, verifying correctness on your machine in various scenarios. If you want to change or optimize Snappy, please run the tests to verify you have not broken anything. Note that if you have the Google Test library installed, unit test behavior (especially failures) will be significantly more user-friendly. You can find Google Test at

http://github.com/google/googletest

You probably also want the gflags library for handling of command-line flags; you can find it at

http://gflags.github.io/gflags/

In addition to the unit tests, snappy contains microbenchmarks used to tune compression and decompression performance. These are automatically run before the unit tests, but you can disable them using the flag --run_microbenchmarks=false if you have gflags installed (otherwise you will need to edit the source).

Finally, snappy can benchmark Snappy against a few other compression libraries (zlib, LZO, LZF, and QuickLZ), if they were detected at configure time. To benchmark using a given file, give the compression algorithm you want to test Snappy against (e.g. --zlib) and then a list of one or more file names on the command line. The testdata/ directory contains the files used by the microbenchmark, which should provide a reasonably balanced starting point for benchmarking. (Note that baddata[1-3].snappy are not intended as benchmarks; they are used to verify correctness in the presence of corrupted data in the unit test.)

Contact

Snappy is distributed through GitHub. For the latest version, a bug tracker, and other information, see

http://google.github.io/snappy/

or the repository at

https://github.com/google/snappy