@nxtedition/deepstream.io-client-js 27.0.0-beta.3 → 27.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto'
|
|
2
|
+
import { Bench } from 'tinybench'
|
|
3
|
+
import { getMsg } from '../src/message/message-builder.js'
|
|
4
|
+
|
|
5
|
+
const bench = new Bench()
|
|
6
|
+
|
|
7
|
+
const name = randomBytes(16).toString('hex')
|
|
8
|
+
const version = randomBytes(16).toString('hex')
|
|
9
|
+
const body = randomBytes(256).toString('hex')
|
|
10
|
+
|
|
11
|
+
function getMsgString(topic, action, data) {
|
|
12
|
+
let msg = `R${topic}U${action}`
|
|
13
|
+
if (data) {
|
|
14
|
+
for (let i = 0; i < data.length; i++) {
|
|
15
|
+
const type = typeof data[i]
|
|
16
|
+
if (data[i] == null) {
|
|
17
|
+
msg += '\u0001'
|
|
18
|
+
msg += ''
|
|
19
|
+
} else if (type === 'object') {
|
|
20
|
+
msg += '\u0001'
|
|
21
|
+
msg += JSON.stringify(data[i])
|
|
22
|
+
} else if (type === 'bigint') {
|
|
23
|
+
msg += '\u0001'
|
|
24
|
+
msg += data[i].toString()
|
|
25
|
+
} else if (type === 'string') {
|
|
26
|
+
msg += '\u0001'
|
|
27
|
+
msg += data[i]
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error('invalid data')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return msg
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bench
|
|
37
|
+
.add('build message string', () => {
|
|
38
|
+
getMsgString('R', 'U', [ name, version, body ])
|
|
39
|
+
})
|
|
40
|
+
.add('build message buffer', () => {
|
|
41
|
+
getMsg('R', 'U', [ name, version, body ])
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
await bench.warmup()
|
|
45
|
+
await bench.run()
|
|
46
|
+
|
|
47
|
+
console.table(bench.table())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/deepstream.io-client-js",
|
|
3
|
-
"version": "27.0.
|
|
3
|
+
"version": "27.0.2",
|
|
4
4
|
"description": "the javascript client for deepstream.io",
|
|
5
5
|
"homepage": "http://deepstream.io",
|
|
6
6
|
"type": "module",
|
|
@@ -84,7 +84,8 @@
|
|
|
84
84
|
"mitata": "^0.1.11",
|
|
85
85
|
"pinst": "^3.0.0",
|
|
86
86
|
"prettier": "^3.3.3",
|
|
87
|
-
"rxjs": "^7.8.1"
|
|
87
|
+
"rxjs": "^7.8.1",
|
|
88
|
+
"tinybench": "^2.8.0"
|
|
88
89
|
},
|
|
89
90
|
"peerDependencies": {
|
|
90
91
|
"rxjs": ">=6.x"
|
|
@@ -51,9 +51,12 @@ export function getMsg(topic, action, data) {
|
|
|
51
51
|
const start = poolOffset
|
|
52
52
|
|
|
53
53
|
const headerSize = 8
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
for (let n = 0; n < headerSize; n++) {
|
|
55
|
+
poolBuffer[poolOffset++] = 0
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let headerPos = start
|
|
59
|
+
poolBuffer[headerPos++] = 128 + headerSize
|
|
57
60
|
|
|
58
61
|
poolBuffer[poolOffset++] = topic.charCodeAt(0)
|
|
59
62
|
poolBuffer[poolOffset++] = 31
|