Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move over to N-API from NAN #71

Merged
merged 13 commits into from
Sep 26, 2019
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ addons:
language: node_js
node_js:
- "12"
- "11"
- "10"
- "9"
- "8"
- "6"
before_install:
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
notifications:
email:
- [email protected]
- [email protected]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2015 Anand Suresh
Copyright (c) 2018-present Anand Suresh

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ benchmark: build
for f in $(BENCHMARK_FILES); do node $$f; done;

clean:
-$(NODE_GYP) clean
$(NODE_GYP) clean


.PHONY: clean build test
120 changes: 60 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
# SSE4-CRC32 [![Build Status](https://travis-ci.org/anandsuresh/sse4_crc32.svg?branch=master)](https://travis-ci.org/anandsuresh/sse4_crc32) [![npm version](https://badge.fury.io/js/sse4_crc32.svg)](http://badge.fury.io/js/sse4_crc32)
# sse4-crc32

Starting with the Nehalam series, Intel processors feature the Streaming SIMD Extensions instruction set which
provide a hardware-accelerated version of the CRC32 algorithm (Castagnoli variant). This library uses the
Intel SSE 4.2 instruction set to provide a fast CRC-32 algorithm.
[![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
## features

- Intel Streaming SIMD Extensions 4.2 based hardware accelerated CRC-32C calculation
- Graceful fallback to software-based CRC (table-based CRC calculation)
- Progressive CRC-32C calculation
- Supports Node.js buffers
- 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

## Performance

The tests were run on a Macbook Air running an Intel Core i7 processor, with 8GB 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.
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:

> node benchmark/1.single_1kb_length_buffer.benchmark.js
100000 calls to calculate CRC on a 1024 byte buffer...
Hardware-based CRC-32C: 27.388368 ms
Software-based CRC-32C: 87.832587 ms
Pure JS CRC-32C (table-based): 726.95698 ms
Pure JS CRC-32C (direct): 4332.993692 ms

> node benchmark/2.multi_random_length_buffer.benchmark.js
100000 calls to calculate CRC on random-length buffers upto 4096 bytes long...
Avg. buffer length: 2049 bytes
Hardware-based CRC-32C: 88.440507 ms
Software-based CRC-32C: 173.136638 ms
Pure JS CRC-32C (table-based): 2131.861339 ms
Pure JS CRC-32C (direct): 9006.901272 ms


## Installation
``` bash
> node benchmark

Use the following command to install the library from npm:

npm install sse4_crc32
single 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 ms


## Usage
multiple 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
```

Using the library is quite simple. Start out by including the library in your code:
## installation

var Sse4Crc32 = require("sse4_crc32");
Use the following command to install the library from npm:

To calculate the 32-bit CRC for any string, simply use the following code:
``` bash
npm install --save sse4_crc32
```

var crc = Sse4Crc32.calculate("my string");
## usage

Instead of passing in a string, a buffer can be passed to the `calculate()` function.
Import the module:

Furthermore, the `calculate()` function takes an optional `initialCrc` value as the second argument, allowing
for progressive CRC calculation.
``` javascript
const Sse4Crc32 = require("sse4_crc32")
```

var crc = Sse4Crc32.calculate("my string");
var newCrc = Sse4Crc32.calculate("my new string", crc);
Calculate the 32-bit CRC for any string:

Another way to calculate CRC in a progressive manner is as follows:
``` javascript
const crc = Sse4Crc32.calculate("my string")
```

var sse4crc32 = new Sse4Crc32.CRC32();
var myInputs = [ "some string", new Buffer("a buffer"), "yet another string", new Buffer("yet another buffer") ];
var crc;
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.

myInputs.forEach(function (string) {
sse4crc32.update(string);
});
``` javascript
const crc = Sse4Crc32.calculate("my string")
const newCrc = Sse4Crc32.calculate("my new string", crc)
```

crc = sse4crc32.crc();
You can also calculate the CRC for streams, as follows:

Also see the example code in the [examples](https://github.com/anandsuresh/sse4_crc32/tree/master/examples)
directory.
``` javascript
const stream = Sse4Crc32
.fromStream(fs.createReadStream('/path/to/file'))
.on('finish', () => console.log(`CRC-32C: ${stream.crc}`))
```

## How to compile
## how to compile

Once the repository has been cloned, use one of the following commands to build the library:

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

``` 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
## contact

All feedback/suggestions/criticisms can be directed to [Anand Suresh](http://www.github.com/anandsuresh)
32 changes: 22 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
version: 0.0.{build}
environment:
matrix:
- nodejs_version: "8"
image:
- Visual Studio 2017
- Visual Studio 2015
- Visual Studio 2013
- nodejs_version: "8"
platform: x64
- nodejs_version: "8"
platform: x86
- nodejs_version: "9"
platform: x64
- nodejs_version: "9"
platform: x86
- nodejs_version: "10"
platform: x64
- nodejs_version: "10"
platform: x86
- nodejs_version: "11"
platform: x64
- nodejs_version: "11"
platform: x86
- nodejs_version: "12"
platform: x64
- nodejs_version: "12"
platform: x86
install:
- ps: Install-Product node $env:nodejs_version x64
# Prepend 2017, 2015 and 2013 tools. Harmless when the path for the other versions don't exist.
- set "PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin;%ProgramFiles(x86)%\MSBuild\14.0\Bin;%ProgramFiles(x86)%\MSBuild\12.0\Bin;%PATH%"
- ps: Install-Product node $env:nodejs_version $env:platform
# Upgrade npm to latest
- npm install --loglevel error -g npm
- set "PATH=%APPDATA%\npm;%PATH%"
- 'if "%nodejs_version%" LEQ 5 (npm install -g npm@5) else (npm install -g npm@latest)'
- node -v
- npm -v
- npm install -g --loglevel error node-gyp
Expand Down
67 changes: 0 additions & 67 deletions benchmark/1.single_1kb_length_buffer.benchmark.js

This file was deleted.

90 changes: 0 additions & 90 deletions benchmark/2.multi_random_length_buffer.benchmark.js

This file was deleted.

Loading