• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    C
  • Created almost 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This make CRC be fast. Included implementations: CRC-64-Jones and CRC-16-CCITT

crcspeed

CRC be slow.

This make CRC be fast.

No original ideas, but original adaptations. Lots of shoulder standing.

This started out as a modified version of comment at http://stackoverflow.com/questions/20562546 then was made more extensible.

NOTE: You should not be using any CRC variant for new code anywhere. All new fast hashing code should use well-designed multi-platform simd-aware libraries like xxh3 and xxh128. Only use CRC in your code if you need to hack together adapters for existing poorly designed systems or if you find yourself time travelling back to the 1970s.

Feature

  • CRC processing in 8-byte steps for CRC-64 (Jones) and CRC-16 (CCITT).
  • Generates CRCs with overhead of 1.5 CPU cycles per byte
  • Little endian and big endian support
    • big endian support hasn't been tested yet (because qemu-system-sparc hates me).
  • Test suite generates comparison for: bit-by-bit calculation, byte-by-byte calcuation (Sarwate / lookup table), and 8-bytes-at-once calculation. Results are reported with resulting CRCs, throughput, and CPU cycles per byte comparisons.

Usage

  • Use little endian CRCs:
    • crc64speed_init();
    • crc64speed(old_crc, new_data, new_data_length);
    • crc16speed_init();
    • crc16speed(old_crc, new_data, new_data_length);
  • Use native architecture CRCs:
    • crc64speed_init_native();
    • crc64speed_native(old_crc, new_data, new_data_length);
    • crc16speed_init_native();
    • crc16speed_native(old_crc, new_data, new_data_length);
  • Use custom CRC64 variant:
    • crcspeed64native_init(crc_calculation_function, uint64_t populate[8][256]);
      • crc calculation function takes (0, data, data_len) and returns crc64 as uint64_t.
      • populate is a lookup table _init populates for future lookups.
    • crcspeed64native(populated_lookup_table, old_crc, new_data, new_data_length);
  • Use custom CRC16 parameters:
    • crcspeed16native_init(crc_calculation_function, uint16_t populate[8][256]);
      • crc calculation function takes (0, data, data_len) and returns crc16 as uint16_t.
    • crcspeed16native(populated_lookup_table, old_crc, new_data, new_data_length);

Additionally, there are specific functions for forcing little or big endian calculations: crcspeed64little_init(), crcspeed64little(), crc64big_init(), crcspeed64big(), crcspeed16little_init(), crcspeed16little(), crc16big_init(), crcspeed16big().

Architecture

  • crcspeed.c is a framework for bootstrapping a fast lookup table using an existing function used to return the CRC for byte values 0 to 255. Lookups then use fast lookup table to calculate CRCs 8 bytes per loop iteration.
  • crc64speed.c is a ready-to-use fast, self-contained CRC-64-Jones implementation.
  • crc16speed.c is a ready-to-use fast, self-contained CRC16-CCITT implementation.
  • when in a multithreaded environment, do not run initialization function(s) in parallel.
  • for fastest CRC calculations, you can force the entire CRC lookup table into CPU caches by running crc64speed_cache_table() or crc16speed_cache_table(). Those functions just iterate over the lookup table to bring everything into local caches out from main memory (or worse, paged out to disk).
  • The CRC-16 lookup table is 4 KB (8x256 16 bit entries = 8 * 256 * 2 bytes = 4096 bytes).
  • The CRC-64 lookup table is 16 KB (8x256 64 bit entires = 8 * 256 * 8 bytes = 16384 bytes).

Benchmark

The Makefile builds three test excutables:

  • crc64speed just returns check values for two input types across all three internal CRC process methods (bit-by-bit, byte-by-byte, 8-bytes-at-once).
  • crc16speed returns check values for the same data, except limited to CRC16 results.
  • crcspeed has two options:
    • no arguments: return check values for crc64 and crc16 at the same time.
    • one argument: filename of file to read into memory then run CRC tests against.
      • If CRC results do not match (for each CRC variant), the return value of crcspeed is 1, otherwise 0 on success.
> mkdir build
> cd build
> cmake ..
> make -j
[ 18%] Building C object CMakeFiles/crcspeed.dir/crc16speed.c.o
[ 27%] Building C object CMakeFiles/crcspeed.dir/crcspeed.c.o
[ 36%] Building C object CMakeFiles/crcspeed.dir/crc64speed.c.o
[ 54%] Building C object CMakeFiles/crc64speed.dir/crc64speed.c.o
[ 54%] Building C object CMakeFiles/crc64speed.dir/crcspeed.c.o
[ 54%] Building C object CMakeFiles/crc16speed.dir/crcspeed.c.o
[ 63%] Building C object CMakeFiles/crc16speed.dir/crc16speed.c.o
[ 72%] Building C object CMakeFiles/crcspeed.dir/main.c.o
[ 81%] Linking C executable crc64speed
[ 90%] Linking C executable crc16speed
[100%] Linking C executable crcspeed
[100%] Built target crc16speed
[100%] Built target crc64speed
[100%] Built target crcspeed

> ./crcspeed ~/Downloads/John\ Mayer\ -\ Live\ At\ Austin\ City\ Limits\ PBS\ -\ Full\ Concert-gcdUz12FkdQ.mp4
Comparing CRCs against 730.72 MB file...

crc64 (no table)
CRC = ee43263b0a2b6c60
7.142642 seconds at 102.30 MB/s (24.18 CPU cycles per byte)

crc64 (lookup table)
CRC = ee43263b0a2b6c60
1.777920 seconds at 411.00 MB/s (6.02 CPU cycles per byte)

crc64speed
CRC = ee43263b0a2b6c60
0.448819 seconds at 1628.09 MB/s (1.52 CPU cycles per byte)

crc16 (no table)
CRC = 000000000000490f
7.413062 seconds at 98.57 MB/s (25.10 CPU cycles per byte)

crc16 (lookup table)
CRC = 000000000000490f
1.951917 seconds at 374.36 MB/s (6.61 CPU cycles per byte)

crc16speed
CRC = 000000000000490f
0.441418 seconds at 1655.38 MB/s (1.49 CPU cycles per byte)

License

All work here is released under BSD or Apache 2.0 License or equivalent.

Thanks

Thanks to Mark Adler for providing a readable implementation of slicing-by-8 in a stackoverflow comment.

Thanks for pycrc for saving me another month figuring out how to write CRC-64-Jones by hand.

Thanks to A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS for providing so many details it was clear I should give up and not try to re-create everything myself.

More Repositories

1

krmt

krmt: Kit of Redis Module Tools
C
118
star
2

icli

interactive brokers ibkr api command line interface cli giving you the fastest way to lose all your money
Python
112
star
3

ib_insync

Live upstream is now at https://github.com/ib-api-reloaded/ib_async; sadly, the orignial creator Ewald has died and now we must continue without his years of experience creating and growing this project. See the 'Discussions' tab for organization planning. Python sync/async framework for Interactive Brokers API
Python
80
star
4

signal-backup

Archive your Signal conversations to immutable storage (project abandoned, but feel free to use as reference if it helps)
HTML
71
star
5

redis-cluster-playground

The simplest way to get a multi-instance Redis Cluster running for experimentation
Shell
57
star
6

ecache

ecache: Erlang ETS Based TTL Cache
Erlang
56
star
7

erlang-stdinout-pool

stdinout_pool: stuff goes in, stuff goes out. there's never any miscommunication.
Erlang
45
star
8

trade-balancer

low latency, high throughput load balancer for real time stock market trade feed (using polygon.io websocket API)
C
35
star
9

redisfuse

FUSE File System for Redis specializing in CRUDing strings and hashes (and R of everything else) (Note: this is obviously ancient and is only a historical artifact now; not really a good example of code usage or design)
Python
33
star
10

stripe-erlang

Erlang interface to the stripe.com API
Erlang
27
star
11

pcache

An Erlang cache where every stored item is its own process.
Erlang
27
star
12

cbuf

Erlang Circular Buffer/List/LIFO Queue using ETS
Erlang
18
star
13

tradeapis

stock market data helpers including api clients for polygon and tradier
Python
15
star
14

datakit

datakit is a collection of the most memory efficient data structures in the universe
C
15
star
15

netmatt

Python implementation of netstat features
Python
14
star
16

pygreeks

calculate exact black-scholes option value using pytorch autograd and also calculate greeks using either autograd or numerical approximation
Python
10
star
17

lematt

Matt's Let's Encrypt Automation
Python
10
star
18

mailweb

Matt's Ansible Roles Integrated For Server-Side Server Serving
Python
10
star
19

er

er: erlang client for redis with erlang-like return values (best erlang client for redis)
Erlang
9
star
20

crc64-compare

Compare a few different CRC-64 implementations
C
9
star
21

oneshot

oneshot: accept a TCP connection then hand it off to a function
Erlang
8
star
22

zog_web

zog_web is a web serving and domain/page routing platform for erlang applications.
Erlang
8
star
23

osxiso

Burn a bootable USB thinggy on OS X from an ISO
Shell
7
star
24

erlwg

erlang rate limiting web getter
Erlang
7
star
25

rat

Redis Analysis Tool
Python
7
star
26

mpreg

Matt’s Protocol for Results Everywhere Guaranteed
Python
7
star
27

restcp

REST TCP Proxy/Router Thing
Erlang
6
star
28

liveconfig

Watch a directory and do something when files change or are added or removed.
Erlang
6
star
29

libgeoip-erlang

erlang bindings to maxmind geoip C API. Imported from bitbucket (very old).
C
5
star
30

car

content-addressed riak
Erlang
5
star
31

cudacam

experiments in cuda, opencv, and kinect under Linux
Python
4
star
32

varint

C functions for multi-paradigm encoding and decoding of variable byte length integers
C
4
star
33

zlang

if you have to ask, you don't want to know. See examples/
Erlang
4
star
34

riak_pool

the simplest erlang pooling riak client
Erlang
4
star
35

twitter-lister

automatically download tweets from your subscribed twitter lists into a full text search database
Python
4
star
36

rets

replicate a redis server's dataset into ets for lower latency access to distributed configurations
Erlang
4
star
37

egsf

erlang general serializing framework
Erlang
4
star
38

etherpad

This is my non-crapified etherpad fix-up. If you want a *base* etherpad, use this (not the ugly "foundation" stuff). Imported from bitbucket.
Java
4
star
39

beas

basic erlang account system
Erlang
3
star
40

balanced-erlang

balancedpayments erlang client
Erlang
3
star
41

redis-perf-compiler

A script to compile tagged versions of Redis many different ways then run benchmarks on each compiled version.
Shell
3
star
42

hnexport

Download all of HN using massively concurrent and pipelined download operations.
Python
3
star
43

chatty

riak and redis backed conversation storage and retrieval
Erlang
2
star
44

cg

config getter
Erlang
2
star
45

git-shrink

Scripts to drop commits from git history and replace history again.
2
star
46

ossmfa

Open Source Software Maintainer Funding Agreement
2
star
47

mutil

matt's python utilities (async/multiprocessing/dataflow)
Python
2
star
48

notifier

redis-backed hierarchical user alerting/notification system
Erlang
2
star
49

hnf

hacker news filter: remove marketing and drivel. Turns Hacker News into Hacked News. Also a testbed for zfeatures.
Erlang
2
star
50

ghost

generalized hierarchical object storage
Erlang
2
star
51

cmake-cpu-detect

Automatic CMake CPU Feature Flag Availability Detection
CMake
2
star
52

tt

tiny table (big table clone using tokyo tyrant proxies)
Erlang
2
star
53

fantasy_payroll

Calculate your potential take home pay taking into account taxes in most states
Erlang
2
star
54

pyjobby

pyjobby: a python+postgres persistent job queue
Python
2
star
55

zog_common

A place for common zcomponents
Erlang
2
star
56

getTV

getTV: an automated TV episode getter using public torrent APIs
Python
2
star
57

nvidia-smi-sender

push nvidia-smi GPU statistics (power, frequency, temperature) to a victoria metrics server at high frequency
Python
2
star
58

racl

redis-backed access control lists
Erlang
1
star
59

weighter

user karma/point/weight management
Erlang
1
star
60

oms-matt

My modifications to Process One's Flash Media Server
JavaScript
1
star
61

attsearch

Use ATT Internet Availability API From CLI
Python
1
star
62

aws-vpc-global-planner

Create multi-account globally unique non-overlapping VPC cidr/subnet configurations for all AZs in all AWS regions
Python
1
star
63

bess

basic erlang session system
Erlang
1
star
64

allegiance

group membership management
Erlang
1
star
65

kapi-python

Python API for managing your historical life timelines including education and location movements over time. Includes a simple CLI so you don't have to write any code to use the API.
Python
1
star
66

geneticfuckery

curious about storing your variables in a database instead of code? want to automatically optimize your variables without building offcial "machine learning" systems? you are welcome to FAFO.
Python
1
star
67

aws-asg-weight-builder

Automation to help you define a collection of allowable instance types to use for automatic scaling operations.
Python
1
star