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

reed-solomon

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reed-solomon - npm Package Compare versions

Comparing version

to
1.1.2

103

benchmark.js

@@ -20,51 +20,66 @@ var ReedSolomon = require('./index.js');

console.log('\nReedSolomon(' + dataShards + ', ' + parityShards + '):');
var binding = ReedSolomon.bindingNative ? 'Native' : 'Javascript';
console.log('Binding: ' + binding);
console.log('');
var encodingResults = [];
var decodingResults = [];
var bindings = [];
if (ReedSolomon.bindingNative) bindings.push(ReedSolomon.bindingNative);
bindings.push(ReedSolomon.bindingJS);
// Benchmark several runs of encoding and decoding.
var times = 5;
while (times--) {
// Encode:
var now = Date.now();
var reedSolomon = new ReedSolomon(dataShards, parityShards);
reedSolomon.encode(shards, 0, shardSize);
var elapsed = (Date.now() - now) / 1000;
var encoded = dataShards * shardSize / (1024* 1024);
var rate = 1 / elapsed * encoded;
encodingResults.push('Encode: ' + rate.toFixed(2) + ' MB/s');
// Decode:
var now = Date.now();
var reedSolomon = new ReedSolomon(dataShards, parityShards);
var shardsPresent = new Array(totalShards);
var length = totalShards;
while (length--) shardsPresent[length] = true;
shards[0] = new Buffer(shardSize);
shardsPresent[0] = false;
shards[1] = new Buffer(shardSize);
shardsPresent[1] = false;
shards[totalShards - 1] = new Buffer(shardSize);
shardsPresent[totalShards - 1] = false;
reedSolomon.decode(shards, 0, shardSize, shardsPresent);
var elapsed = (Date.now() - now) / 1000;
var decoded = dataShards * shardSize / (1024* 1024);
var rate = 1 / elapsed * decoded;
decodingResults.push('Decode: ' + rate.toFixed(2) + ' MB/s');
}
bindings.forEach(
function(binding) {
if (binding === undefined) throw new Error('Binding not defined.');
if (binding === ReedSolomon.bindingNative) {
var bindingName = 'Native';
} else {
var bindingName = 'Javascript';
}
console.log('Binding: ' + bindingName);
console.log('');
// Group the encoding and decoding results:
encodingResults.forEach(
function(encodingResult) {
console.log(encodingResult);
var encodingResults = [];
var decodingResults = [];
// Benchmark several runs of encoding and decoding.
var times = 5;
while (times--) {
// Encode:
var now = Date.now();
var reedSolomon = new ReedSolomon(dataShards, parityShards, binding);
reedSolomon.encode(shards, 0, shardSize);
var elapsed = (Date.now() - now) / 1000;
var encoded = dataShards * shardSize / (1024* 1024);
var rate = 1 / elapsed * encoded;
encodingResults.push('Encode: ' + rate.toFixed(2) + ' MB/s');
// Decode:
var now = Date.now();
var reedSolomon = new ReedSolomon(dataShards, parityShards, binding);
var shardsPresent = new Array(totalShards);
var length = totalShards;
while (length--) shardsPresent[length] = true;
shards[0] = new Buffer(shardSize);
shardsPresent[0] = false;
shards[1] = new Buffer(shardSize);
shardsPresent[1] = false;
shards[totalShards - 1] = new Buffer(shardSize);
shardsPresent[totalShards - 1] = false;
reedSolomon.decode(shards, 0, shardSize, shardsPresent);
var elapsed = (Date.now() - now) / 1000;
var decoded = dataShards * shardSize / (1024* 1024);
var rate = 1 / elapsed * decoded;
decodingResults.push('Decode: ' + rate.toFixed(2) + ' MB/s');
}
// Group the encoding and decoding results:
encodingResults.forEach(
function(encodingResult) {
console.log(encodingResult);
}
);
console.log('');
decodingResults.forEach(
function(decodingResult) {
console.log(decodingResult);
}
);
console.log('');
}
);
console.log('');
decodingResults.forEach(
function(decodingResult) {
console.log(decodingResult);
}
);
console.log('');
{
"name": "reed-solomon",
"version": "1.1.1",
"version": "1.1.2",
"description": "Reed-Solomon erasure coding in pure Javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,8 +16,6 @@ # reed-solomon

## Performance
`reed-solomon` includes a Javascript binding as well as an optional native binding (and simple benchmark):
`reed-solomon` includes a Javascript binding as well as an optional native binding:
```
ReedSolomon(17, 3)
ReedSolomon(17, 3) [1,8 GHz Intel Core i5]:
1,8 GHz Intel Core i5
Binding: Native

@@ -34,4 +32,4 @@

## Optional Native Binding
The native binding will be installed by default when installing `reed-solomon`, and the Javascript binding will be used if the native binding could not be compiled. To compile the native binding manually, install [node-gyp](https://www.npmjs.com/package/node-gyp) globally:
## Native Binding (Optional)
The native binding will be installed automatically when installing `reed-solomon`, and the Javascript binding will be used if the native binding could not be compiled. To compile the native binding manually, install [node-gyp](https://www.npmjs.com/package/node-gyp) globally:
```

@@ -104,5 +102,12 @@ sudo npm install node-gyp -g

`reed-solomon` ships with extensive tests, including a long-running fuzz test.
To test the native and Javascript bindings:
```
cd node-modules/reed-solomon
node test.js
```
## Benchmark
To benchmark the native and Javascript bindings:
```
node benchmark.js
```