Socket
Socket
Sign inDemoInstall

sse4_crc32

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sse4_crc32

Hardware-accelerated CRC32 based on Intel Streaming SIMD Extensions 4.2


Version published
Weekly downloads
46K
decreased by-1.57%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Features

  • Intel Streaming SIMD Extensions 4.2 based hardware accelerated CRC 32 calculation
  • Progressive CRC32 calculation
  • Supports Node.js buffers

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.

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...
        SSE4.2 based CRC32: 26ms.
        Pure JS based CRC32 (table-based): 699ms.
        Pure JS based CRC32 (direct): 3704ms.

>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: 2042 bytes
        SSE4.2 based CRC32: 62ms.
        Pure JS based CRC32 (table-based): 1968ms.
        Pure JS based CRC32 (direct): 8220ms.

As you can see, the SSE4_CRC32 library is about 31.74 times faster than the pure JS library!

Installation

Use the following command to install the library from npm:

npm install sse4_crc32

Usage

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

var SSE4CRC32 = require("sse4_crc32");

To calculate the 32-bit CRC for any string, simply use the following code:

var crc = SSE4CRC32.calculate("my string");

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

To calculate CRC in a progressive manner, use the code snippet:

var SSE4CRC32 = new SSE4CRC32.CRC32(),
	my_inputs = [ "some string", new Buffer("a buffer"), "yet another string", new Buffer("yet another buffer") ],
	crc;

my_inputs.forEach(function (string) {
	crc = SSE4CRC32.update(string);
});

crc = SSE4CRC32.crc();				// The .crc() method can also be used to get the final CRC

Also see the example code in the examples directory.

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

Contact

All feedback/suggestions/criticisms can be directed to Anand Suresh

Keywords

FAQs

Package last updated on 08 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc