generated from streamich/tpl-ts-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const Benchmark = require('benchmark'); | ||
const {connectShort, connectWithProperties} = require('./packets'); | ||
const {MqttDecoder} = require('../es6/MqttDecoder'); | ||
const mqtt = require('mqtt-packet'); | ||
|
||
const decoder = new MqttDecoder(); | ||
const parser = mqtt.parser(); | ||
|
||
const suite = new Benchmark.Suite; | ||
suite | ||
.add('mqtt-codec (CONNECT short)', function() { | ||
decoder.push(Buffer.from(connectShort)); | ||
packet = decoder.parse(); | ||
}) | ||
.add('mqtt-codec (CONNECT long with properties)', function() { | ||
decoder.push(Buffer.from(connectWithProperties)); | ||
packet = decoder.parse(); | ||
}) | ||
.add('mqtt-packet (CONNECT short)', function() { | ||
parser.parse(Buffer.from(connectShort)); | ||
}) | ||
.add('mqtt-packet (CONNECT long with properties)', function() { | ||
parser.parse(Buffer.from(connectWithProperties)); | ||
}) | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
.run(); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const packets = { | ||
connectWithProperties: [ | ||
16, 125, // Header | ||
0, 4, // Protocol ID length | ||
77, 81, 84, 84, // Protocol ID | ||
5, // Protocol version | ||
54, // Connect flags | ||
0, 30, // Keepalive | ||
47, // properties length | ||
17, 0, 0, 4, 210, // sessionExpiryInterval | ||
33, 1, 176, // receiveMaximum | ||
39, 0, 0, 0, 100, // maximumPacketSize | ||
34, 1, 200, // topicAliasMaximum | ||
25, 1, // requestResponseInformation | ||
23, 1, // requestProblemInformation, | ||
38, 0, 4, 116, 101, 115, 116, 0, 4, 116, 101, 115, 116, // userProperties, | ||
21, 0, 4, 116, 101, 115, 116, // authenticationMethod | ||
22, 0, 4, 1, 2, 3, 4, // authenticationData | ||
0, 4, // Client ID length | ||
116, 101, 115, 116, // Client ID | ||
47, // will properties | ||
24, 0, 0, 4, 210, // will delay interval | ||
1, 0, // payload format indicator | ||
2, 0, 0, 16, 225, // message expiry interval | ||
3, 0, 4, 116, 101, 115, 116, // content type | ||
8, 0, 5, 116, 111, 112, 105, 99, // response topic | ||
9, 0, 4, 1, 2, 3, 4, // corelation data | ||
38, 0, 4, 116, 101, 115, 116, 0, 4, 116, 101, 115, 116, // user properties | ||
0, 5, // Will topic length | ||
116, 111, 112, 105, 99, // Will topic | ||
0, 4, // Will payload length | ||
4, 3, 2, 1// Will payload | ||
], | ||
|
||
connectShort: [ | ||
16, 16, | ||
0, 4, 77, 81, 84, 84, // Protocol name | ||
4, // Version | ||
2, // Flags | ||
0, 0, // Keep-alive | ||
0, 4, 116, 101, 115, 116 // Client ID "test" | ||
], | ||
|
||
connackShort: [ | ||
32, 2, 0, 0 | ||
], | ||
|
||
connackWithProperties: [ | ||
32, 100, 0, 0, | ||
97, // properties length | ||
17, 0, 0, 4, 210, // sessionExpiryInterval | ||
33, 1, 176, // receiveMaximum | ||
36, 2, // Maximum qos | ||
37, 1, // retainAvailable | ||
39, 0, 0, 0, 100, // maximumPacketSize | ||
18, 0, 4, 116, 101, 115, 116, // assignedClientIdentifier | ||
34, 1, 200, // topicAliasMaximum | ||
31, 0, 4, 116, 101, 115, 116, // reasonString | ||
38, 0, 4, 116, 101, 115, 116, 0, 4, 116, 101, 115, 116, | ||
38, 0, 4, 116, 101, 115, 116, 0, 4, 116, 101, 115, 116, // userProperties | ||
40, 1, // wildcardSubscriptionAvailable | ||
41, 1, // subscriptionIdentifiersAvailable | ||
42, 0, // sharedSubscriptionAvailable | ||
19, 4, 210, // serverKeepAlive | ||
26, 0, 4, 116, 101, 115, 116, // responseInformation | ||
28, 0, 4, 116, 101, 115, 116, // serverReference | ||
21, 0, 4, 116, 101, 115, 116, // authenticationMethod | ||
22, 0, 4, 1, 2, 3, 4 // authenticationData | ||
], | ||
}; | ||
|
||
exports.packets = packets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const Benchmark = require('benchmark'); | ||
const {packets} = require('./packets'); | ||
const {MqttDecoder} = require('../es6/MqttDecoder'); | ||
const mqtt = require('mqtt-packet'); | ||
|
||
const suite = new Benchmark.Suite; | ||
|
||
for (const name of Object.keys(packets)) { | ||
suite | ||
.add(`mqtt-codec (${name})`, function() { | ||
const decoder = new MqttDecoder(); | ||
decoder.push(Buffer.from(packets[name])); | ||
decoder.parse(); | ||
}) | ||
.add(`mqtt-packet (${name})`, function() { | ||
const parser = mqtt.parser(); | ||
parser.parse(Buffer.from(packets[name])); | ||
}); | ||
} | ||
|
||
suite | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const Benchmark = require('benchmark'); | ||
const {connectShort, connectWithProperties} = require('./packets'); | ||
const {MqttDecoder} = require('../es6/MqttDecoder'); | ||
const {PacketConnect} = require('../es6/packets/connect'); | ||
const mqtt = require('mqtt-packet'); | ||
const parser = mqtt.parser(); | ||
let packet; | ||
parser.on('packet', p => packet = p); | ||
parser.parse(Buffer.from(connectShort)); | ||
console.log(packet); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import BufferList from 'bl'; | ||
import {PACKET_TYPE} from './enums'; | ||
import {QoS} from './types'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters