Out-of-order friendly portable implementation. Baseline, HP Z840: CRC32CBenchmark/Portable/256 222 ns 3194027 1100.84MB/s CRC32CBenchmark/Portable/4096 3425 ns 203898 1.11364GB/s CRC32CBenchmark/Portable/65536 55218 ns 12601 1.10533GB/s CRC32CBenchmark/Portable/1048576 861817 ns 806 1.13313GB/s CRC32CBenchmark/Portable/16777216 13765400 ns 51 1.13509GB/s New, HP Z840: CRC32CBenchmark/Portable/256 94 ns 7490593 2.5386GB/s CRC32CBenchmark/Portable/4096 1052 ns 677653 3.62485GB/s CRC32CBenchmark/Portable/65536 16614 ns 41142 3.67378GB/s CRC32CBenchmark/Portable/1048576 258028 ns 2645 3.78474GB/s CRC32CBenchmark/Portable/16777216 4163669 ns 165 3.75276GB/s Baseline, Google Pixel C: CRC32CBenchmark/Portable/256 372 ns 1885103 657.405MB/s CRC32CBenchmark/Portable/4096 5743 ns 122160 681.409MB/s CRC32CBenchmark/Portable/65536 91958 ns 7618 680.341MB/s CRC32CBenchmark/Portable/1048576 1477922 ns 473 677.23MB/s CRC32CBenchmark/Portable/16777216 24189925 ns 29 662.115MB/s New, Google Pixel C: CRC32CBenchmark/Portable/256 248 ns 2826799 986.005MB/s CRC32CBenchmark/Portable/4096 2923 ns 240216 1.30804GB/s CRC32CBenchmark/Portable/65536 45687 ns 15335 1.33688GB/s CRC32CBenchmark/Portable/1048576 746816 ns 944 1.30887GB/s CRC32CBenchmark/Portable/16777216 12372240 ns 57 1.26483GB/s
This is not an official Google product. This is code extracted from LevelDB, which is a stable key-value store that is widely used at Google.
This project collects a few CRC32C implementations under an umbrella that dispatches to a suitable implementation based on the host computer's hardware capabilities.
CRC32C is specified as the CRC that uses the iSCSI polynomial in RFC 3720. The polynomial was introduced by G. Castagnoli, S. Braeuer and M. Herrmann. CRC32C is used in software such as Btrfs, ext4, Ceph and leveldb.
#include "crc32c/crc32c.h" int main() { const std::uint8_t buffer[] = {0, 0, 0, 0}; std::uint32_t result; // Process a raw buffer. result = crc32c::Crc32c(buffer, 4); // Process a std::string. std::string string; string.resize(4); result = crc32c::Crc32c(string); // If you have C++17 support, process a std::string_view. std::string_view string_view(string); result = crc32c::Crc32c(string_view); return 0; }
This project uses CMake for building and testing. CMake is available in all popular Linux distributions, as well as in Homebrew.
This project uses submodules for dependency management.
git submodule update --init --recursive
If you're using Atom, the following packages can help.
apm install autocomplete-clang build build-cmake clang-format language-cmake \ linter linter-clang
If you don't mind more setup in return for more speed, replace autocomplete-clang and linter-clang with you-complete-me. This requires setting up ycmd.
apm install autocomplete-plus build build-cmake clang-format language-cmake \ linter you-complete-me
The following commands build and install the project.
mkdir out cd out cmake -DCRC32C_BUILD_TESTS=0 -DCRC32C_BUILD_BENCHMARKS=0 .. && make all install
The following command (when executed from out/) (re)builds the project and runs the tests.
cmake .. && cmake --build . && ctest --output-on-failure
The following command builds the project against the Android NDK, which is useful for benchmarking against ARM processors.
cmake .. -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ -DCMAKE_ANDROID_NDK=$HOME/Library/Android/sdk/ndk-bundle \ -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang -DCRC32C_USE_GLOG=0 \ -DCMAKE_BUILD_TYPE=Release && cmake --build .
The following commands install and run the benchmarks.
adb push crc32c_bench /data/local/tmp adb shell chmod +x /data/local/tmp/crc32c_bench adb shell 'cd /data/local/tmp && ./crc32c_bench' adb shell rm /data/local/tmp/crc32c_bench
The following commands install and run the tests.
adb push crc32c_tests /data/local/tmp adb shell chmod +x /data/local/tmp/crc32c_tests adb shell 'cd /data/local/tmp && ./crc32c_tests' adb shell rm /data/local/tmp/crc32c_tests