forked from miketout/verushash-node
-
Notifications
You must be signed in to change notification settings - Fork 23
/
test.js
42 lines (33 loc) · 1.72 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var cluster = require('cluster');
var vh = require('bindings')('verushash.node');
var reverseBuffer = function (buff) {
var reversed = Buffer.alloc(buff.length);
for (var i = buff.length - 1; i >= 0; i--)
reversed[buff.length - i - 1] = buff[i];
return reversed;
};
var reverseHex = function (hex) {
return reverseBuffer(Buffer.from(hex, 'hex')).toString('hex');
};
var numWorkers = require('os').cpus().length;
numWorkers = 1; /* increase for multi-thread testing of data collision */
if (cluster.isMaster) {
var workers = [];
var gbtCount = 0;
for (var i = 0; i < numWorkers; i++){
var worker = cluster.fork({
workerType: 'VerusHasher',
forkId: i
});
workers.push(worker);
}
} else {
var output = vh.hash(Buffer.from('Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234','utf8'));
console.log(process.pid,'VerusHash1 Output', reverseHex(output.toString('hex')), '\n');
output = vh.hash2(Buffer.from('Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234','utf8'));
console.log(process.pid,'VerusHash2 Output', reverseHex(output.toString('hex')), '\n');
output = vh.hash2b(Buffer.from('Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234','utf8'));
console.log(process.pid,'VerusHash2b Output', reverseHex(output.toString('hex')), '\n');
output = vh.hash2b1(Buffer.from('Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234Test1234','utf8'));
console.log(process.pid,'VerusHash2b1 Output', reverseHex(output.toString('hex')), '\n');
}