Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anandsuresh/sse4_crc32
SSE4.2-based H/w-accelerated CRC32 calculator with software fallback
https://github.com/anandsuresh/sse4_crc32
Last synced: 17 days ago
JSON representation
SSE4.2-based H/w-accelerated CRC32 calculator with software fallback
- Host: GitHub
- URL: https://github.com/anandsuresh/sse4_crc32
- Owner: anandsuresh
- License: mit
- Created: 2013-11-07T18:48:56.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-07-08T22:49:08.000Z (over 1 year ago)
- Last Synced: 2024-07-31T22:53:15.282Z (3 months ago)
- Language: C++
- Homepage:
- Size: 205 KB
- Stars: 131
- Watchers: 12
- Forks: 31
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sse4-crc32
[![node (scoped)](https://img.shields.io/node/v/sse4_crc32.svg?style=plastic)](https://nodejs.org/en/download/)
[![npm (scoped)](https://img.shields.io/npm/v/sse4_crc32.svg?style=plastic)](https://www.npmjs.com/package/sse4_crc32)
[![npm](https://img.shields.io/npm/dt/sse4_crc32.svg?style=plastic)](https://www.npmjs.com/package/sse4_crc32)
[![Travis](https://img.shields.io/travis/anandsuresh/sse4_crc32.svg?style=plastic)](https://travis-ci.org/anandsuresh/sse4_crc32)
[![license](https://img.shields.io/github/license/anandsuresh/sse4_crc32.svg?style=plastic)](LICENSE)
[![GitHub followers](https://img.shields.io/github/followers/anandsuresh.svg?style=social&label=Follow)](https://github.com/anandsuresh)
[![Twitter Follow](https://img.shields.io/twitter/follow/anandsuresh.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=anandsuresh)Starting with the Nehalam series, Intel processors feature the Streaming SIMD Extensions instruction set which provide a hardware-accelerated version of the CRC-32 algorithm (Castagnoli variant). This library uses the Intel SSE 4.2 instruction set to provide a fast CRC-32C implementation.
## features
- Intel Streaming SIMD Extensions 4.2 based hardware-accelerated CRC-32C calculation
- Graceful fallback to software-based CRC-32C (table-based CRC calculation)
- Supports streams, strings and buffers## performance
The tests were run on a Macbook Air running an Intel Core i7 processor, with 16GB of RAM and used buffers instead of strings to prevent having items on the V8 heap that might cause the garbage collector to fire frequently and interfere with the test run-times.
Below are the results from the 2 test cases:
``` bash
> node benchmarksingle fixed-size buffer, 10000 iterations:
- Native SSE 4.2 CRC-32C: 4.319142 ms
- Native Table-based CRC-32C: 10.726345 ms
- JavaScript (table-based) CRC-32C: 60.704765 ms
- JavaScript (direct) CRC-32C: 336.376904 msmultiple random-length buffers, 10000 iterations:
- Native SSE 4.2 CRC-32C: 60.194043 ms
- Native Table-based CRC-32C: 225.459861 ms
- JavaScript (table-based) CRC-32C: 1786.079168 ms
- JavaScript (direct) CRC-32C: 12307.033387 ms
```## installation
Use the following command to install the library from npm:
``` bash
npm install --save sse4_crc32
```## usage
Import the module:
``` javascript
const Sse4Crc32 = require("sse4_crc32")
```Calculate the 32-bit CRC for any string:
``` javascript
const crc = Sse4Crc32.calculate("my string")
```Instead of passing in a string, a buffer can be passed to the `calculate()` function. Furthermore, the `calculate()` function takes an optional `initialCrc` value as the second argument, allowing for progressive CRC calculation.
``` javascript
const crc = Sse4Crc32.calculate("my string")
const newCrc = Sse4Crc32.calculate("my new string", crc)
```You can also calculate the CRC for streams, as follows:
``` javascript
const stream = Sse4Crc32
.fromStream(fs.createReadStream('/path/to/file'))
.on('finish', () => console.log(`CRC-32C: ${stream.crc}`))
```## how to compile
Once the repository has been cloned, use one of the following commands to build the library:
``` bash
make all // Builds the release version of the library and runs all tests
make debug // Builds the debug version of the library
make clean // Removes all files generated by builds
```## contact
All feedback/suggestions/criticisms can be directed to [Anand Suresh](http://www.github.com/anandsuresh)