Skip to content

Commit 12aeb53

Browse files
committed
return function from benchmark module (implementation still WIP) so that banchmark don't crash. Fixes #368
1 parent 1e1de36 commit 12aeb53

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

benchmarks/unit/packet_parser.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,50 @@ while(1) {
1919

2020
var PP = require('../../lib/packet_parser.js');
2121

22-
var count = 0;
23-
var cc = 0;
22+
var chunks = [];
23+
function benchmarkPackets() {
2424

25-
function handler(packet) {
26-
//console.log(packet.length(), packet.sequenceId);
27-
cc += packet.sequenceId
28-
count++;
29-
}
25+
if (chunks.length === 0) {
26+
for (var csize = 1; csize < plen; ++csize) {
27+
for (var o=0; o + csize < p.length; o += csize) {
28+
chunks.push(p.slice(o, o+csize));
29+
}
30+
}
31+
}
3032

31-
var chunks = [];
32-
var csize = parseInt(process.argv[2]);
33-
for (var o=0; o + csize < p.length; o += csize) {
34-
chunks.push(p.slice(o, o+csize));
35-
}
33+
console.log(chunks);
3634

37-
var start = process.hrtime();
38-
for (var i=0; i < 50; ++i) {
35+
var count = 0;
36+
var cc = 0;
37+
38+
function handler(packet) {
39+
//console.log(packet.length(), packet.sequenceId);
40+
cc += packet.sequenceId
41+
count++;
42+
}
43+
44+
var start = process.hrtime();
3945
var packetParser = new PP(handler);
4046
for (var j=0; j < chunks.length; ++j) {
4147
packetParser.execute(chunks[j]);
4248
}
49+
return count;
50+
}
51+
52+
module.exports = function(next) {
53+
/*
54+
var c = benchmarkPackets();
55+
*/
56+
next();
4357
}
44-
var end = process.hrtime(start);
45-
var dur = end[0]*1e9 + end[1];
4658

47-
console.log(1e9*count/dur, count, cc);
59+
module.exports.comment = 'WIP - not implemented yet | packet_parser.execute() in chunks of length 1..packet_length x 156035 packets';
60+
module.exports.toSpeed = function(time, timeError) {
61+
console.log('packet_parser.execute() toSpeed()', time, timeError);
62+
var value = 1e9*5*156975 / time;
63+
return {
64+
value: value,
65+
error: value*(timeError/time),
66+
units: 'packets/second'
67+
};
68+
};

0 commit comments

Comments
 (0)