New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

crc32c

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crc32c - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

96

benchmarks/benchmarks.js
/**
* Dependencies
*/
var SSE4CRC32 = require("sse4_crc32");
// var SSE4CRC32 = require("sse4_crc32");
var js_crc32 = require("crc32");

@@ -17,8 +17,8 @@ var c_crc32 = require("../bin/crc32c");

var tests = {
TEST_STRING_1024 : String1024,
TEST_STRING_2048 : String2048,
TEST_BUFFER_1024 : new Buffer( String1024 ),
TEST_BUFFER_2048 : new Buffer( String2048 ),
TEST_STRING_OBJECT_1024 : new String( String1024 ),
TEST_STRING_OBJECT_2048 : new String( String2048 )
TEST_STRING_1024 : String1024,
TEST_STRING_2048 : String2048,
TEST_BUFFER_1024 : new Buffer( String1024 ),
TEST_BUFFER_2048 : new Buffer( String2048 ),
TEST_STRING_OBJECT_1024 : new String( String1024 ),
TEST_STRING_OBJECT_2048 : new String( String2048 )
};

@@ -40,10 +40,10 @@

Object.keys(tests).forEach(function (key) {
label = "\t" + key;
console.time(label);
batcher.openSocket();
for (var i = 0; i < N; i++) {
crc = batcher.compute(tests[key]);
}
batcher.closeSocket();
console.timeEnd(label);
label = "\t" + key;
console.time(label);
batcher.openSocket();
for (var i = 0; i < N; i++) {
crc = batcher.compute(tests[key]);
}
batcher.closeSocket();
console.timeEnd(label);
});

@@ -53,25 +53,25 @@

Object.keys(tests).forEach(function (key) {
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = c_crc32.compute(tests[key]);
}
console.timeEnd(label);
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = c_crc32.compute(tests[key]);
}
console.timeEnd(label);
});
/**
* sse_crc32
*/
console.log('%d calls to calculate CRC with SSE4.2...', N);
Object.keys(tests).forEach(function (key) {
// Does not support String Objects
if (!key.match(/STRING_OBJECT/)) {
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = SSE4CRC32.calculate(tests[key]);
}
console.timeEnd(label);
}
});
// /**
// * sse_crc32
// */
// console.log('%d calls to calculate CRC with SSE4.2...', N);
// Object.keys(tests).forEach(function (key) {
// // Does not support String Objects
// if (!key.match(/STRING_OBJECT/)) {
// label = "\t" + key;
// console.time(label);
// for (var i = 0; i < N; i++) {
// crc = SSE4CRC32.calculate(tests[key]);
// }
// console.timeEnd(label);
// }
// });

@@ -83,8 +83,8 @@ /**

Object.keys(tests).forEach(function (key) {
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = js_crc32(tests[key], false);
}
console.timeEnd(label);
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = js_crc32(tests[key], false);
}
console.timeEnd(label);
});

@@ -94,8 +94,8 @@

Object.keys(tests).forEach(function (key) {
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = js_crc32(tests[key], true);
}
console.timeEnd(label);
label = "\t" + key;
console.time(label);
for (var i = 0; i < N; i++) {
crc = js_crc32(tests[key], true);
}
console.timeEnd(label);
});

@@ -7,4 +7,4 @@ ;(function () {

if(process.argv.length < 3) {
console.err('Expected an argument');
console.log('Correct usage: crc32c <filename>');
console.err('Expected an argument');
console.log('Correct usage: crc32c <filename>');
}

@@ -24,5 +24,5 @@

s.on('end', function () {
console.log(crc32c.compute(Buffer.concat(dataChunks)));
console.log(crc32c.compute(Buffer.concat(dataChunks)));
});
})(); /* end of anonymous function */
{
"name": "crc32c",
"version": "0.4.2",
"description": "CRC32C C implementation for Linux. Supports strings, String Objects and Buffers!",
"keywords": [ "crc", "crc32", "crc32c", "hash", "castagnoli" ],
"author": "Hugo Dozois <hugo@dozoisch.com>",
"license": "MIT",
"dependencies" : {},
"devDependencies" : {
"crc32": "latest",
"sse4_crc32": "latest",
"mongoose": "latest"
},
"main": "./bin/crc32c.node",
"repository": {
"type": "git",
"url": "https://github.com/dozoisch/node-crc32c.git"
},
"bin": { "crc32c": "./crc32c" },
"files": [
"LICENSE",
"README.md",
"src",
"test",
"benchmarks",
"binding.gyp",
"crc32c",
"bin/crc32c-cli.js"
],
"scripts": {
"test": "node test/test.js"
},
"engines": {
"node": ">= 0.10.0"
},
"os" : [ "linux" ]
"name": "crc32c",
"version": "0.5.0",
"description": "CRC32C C implementation for Linux. Supports strings, String Objects and Buffers!",
"keywords": [
"crc",
"crc32",
"crc32c",
"hash",
"castagnoli"
],
"author": "Hugo Dozois <hugo@dozoisch.com>",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"crc32": "latest",
"mocha": "1.20.x",
"should": "4.0.x"
},
"main": "./bin/crc32c.node",
"repository": {
"type": "git",
"url": "https://github.com/dozoisch/node-crc32c.git"
},
"bin": {
"crc32c": "./crc32c"
},
"files": [
"LICENSE",
"README.md",
"src",
"test",
"benchmarks",
"binding.gyp",
"crc32c",
"bin/crc32c-cli.js"
],
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/mocha --harmony --reporter spec ./test/test.js"
},
"engines": {
"node": ">= 0.10.0"
},
"os": [
"linux"
]
}
Node-crc32c
===========
[![Build Status][travis.img]][travis.url]
Basic C modules for NodeJS with crc32c (Castagnoli) implementation for Linux. The implementation uses the native Linux library "AF\_ALG".
It is compatible with node 0.10 and 0.11!

@@ -12,3 +15,3 @@ It supports strings, string objects, buffers, numbers! Works well with mongoose. Just do a toString on the entity to hash!

node-gyp configure build
make build

@@ -74,5 +77,9 @@ or

## Tests
You can run the test by doing `make test`. Currently the test only contains successful use case, but error handling test cases will be added soon.
## Benchmarks
Run the script by doing `node benchmarks/benchmarks.js`!
Run the script by doing `make benchmarks`!

@@ -106,1 +113,4 @@ *I think that pure times are not representative of reality, since every setup will get different results. This is why I've put the times in ratio using AF_ALG batch as the base (1).*

- The pure JS library is waaaaaaaaaay slower with 1024 bytes strings and gets slower and slower when the string is bigger. The C implementation is pretty stable, and the only thing slowing it in the unboxing from JavaScript to pure C.
[travis.img]: https://api.travis-ci.org/dozoisch/node-crc32c.svg
[travis.url]: https://travis-ci.org/dozoisch/node-crc32c
'use strict';
var crc32c = require('../bin/crc32c');
var should = require('should');

@@ -16,30 +17,65 @@ // 1024b ytes

var tests = {
TEST_STRING_1024 : String1024,
TEST_STRING_2048 : String2048,
TEST_BUFFER_1024 : new Buffer( String1024 ),
TEST_BUFFER_2048 : new Buffer( String2048 ),
TEST_STRING_OBJECT_1024 : new String( String1024 ),
TEST_STRING_OBJECT_2048 : new String( String2048 ),
TEST_INTEGER_1: n_int_1,
TEST_INTEGER_2: n_int_2,
TEST_FLOAT_1: n_float_1,
TEST_FLOAT_2: n_float_2
TEST_STRING_1024 : String1024,
TEST_STRING_2048 : String2048,
TEST_BUFFER_1024 : new Buffer( String1024 ),
TEST_BUFFER_2048 : new Buffer( String2048 ),
TEST_STRING_OBJECT_1024 : new String( String1024 ),
TEST_STRING_OBJECT_2048 : new String( String2048 ),
TEST_INTEGER_1: n_int_1,
TEST_INTEGER_2: n_int_2,
TEST_FLOAT_1: n_float_1,
TEST_FLOAT_2: n_float_2
};
// Expected results for different test cases
var expectedResults = [
1796588439, // TEST_STRING_1024 :
-239795962, // TEST_STRING_2048
1796588439, // TEST_BUFFER_1024
-239795962, // TEST_BUFFER_2048
1796588439, // TEST_STRING_OBJECT_1024
-239795962, // TEST_STRING_OBJECT_2048
786278885, // TEST_INTEGER_1
386556866, // TEST_INTEGER_2
1859275355, // TEST_FLOAT_1
1217071852, // TEST_FLOAT_2
];
//*** Standard way
console.log("Calls to calculate CRC with CRC32C AF_ALG, multi sockets...");
Object.keys(tests).forEach(function (key) {
console.log("\t" + key + ": " + crc32c.compute(tests[key]));
//*** Standard
describe('Multi Socket (Standard)', function () {
Object.keys(tests).forEach(function (key, index) {
it('should compute for ' + key, function (done) {
var result = crc32c.compute(tests[key]);
should.exist(result);
result.should.equal(expectedResults[index]);
done();
});
});
});
//*** Batcher
var batcher = new crc32c.Batcher();
console.log("\nCalls to calculate CRC with CRC32C AF_ALG, single socket...");
batcher.openSocket();
Object.keys(tests).forEach(function (key) {
console.log("\t" + key + ": " + batcher.compute(tests[key]));
describe('Single Socket (Batcher)', function () {
var batcher;
before(function (done) {
batcher = new crc32c.Batcher();
batcher.openSocket();
done();
});
Object.keys(tests).forEach(function (key, index) {
it('should compute for ' + key, function (done) {
var result = batcher.compute(tests[key]);
should.exist(result);
result.should.equal(expectedResults[index]);
done();
});
});
after(function (done) {
batcher.closeSocket();
done();
});
});
batcher.closeSocket();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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