Snappy Compression Library

repository·main·Indexed 27 days ago

https://github.com/google/snappy

A high-speed compression/decompression library written in C++ with C bindings, designed for very high speeds and reasonable compression ratios rather than maximum density. It is optimized for performance, offering compression speeds of ~250 MB/sec or more and decompression speeds of ~500 MB/sec or more on a single Core i7 64-bit core.

Tokens
999
Snippets
2
Records
6
Agent score
42%

What's inside Snappy

  1. Overview of Snappy compression

    main

    Snappy is a high-speed compression/decompression library designed for very high speeds and reasonable compression ratios rather than maximum compression. It is optimized for performance, often being an order of magnitude faster than the fastest mode of zlib, though resulting files may be 20% to 100% larger.

    Key performance characteristics (on a single Core i7 64-bit core):

    • Compression: ~250 MB/sec or more
    • Decompression: ~500 MB/sec or more.
  2. Build Snappy from source

    main

    To build Snappy, you must have the version of CMake specified in the CMakeLists.txt file or a later version installed. Follow these steps to initialize submodules and compile the library using CMake and Make:

    git submodule update --init
    mkdir build
    cd build && cmake ../ && make
  3. Use Snappy in C++

    main

    Snappy is implemented in C++. To use it in your C++ application, include snappy.h in your source files and link against the compiled Snappy library. The simplest way to compress and decompress data is using std::string objects for both input and output.

    snappy::Compress(input.data(), input.size(), &output);
    
    // To decompress:
    snappy::Uncompress(input.data(), input.size(), &output);
  4. Run Snappy benchmarks and tests

    main

    When you build the project, several utility binaries are created. These are useful for verifying correctness and performance on your specific hardware:

    • snappy_benchmark: Contains microbenchmarks for tuning performance.
    • snappy_unittests: Contains unit tests to verify correctness.
    • snappy_test_tool: Benchmarks Snappy against other libraries (like zlib, LZO, LZF, or QuickLZ) if they were detected during configuration. To use it, provide a flag for the target algorithm (e.g., --zlib) followed by the file names to test.
  5. Available language bindings for Snappy

    main

    While written in C++ and including C bindings, Snappy is available for many other languages through third-party implementations and wrappers: