-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_old.js
70 lines (61 loc) · 2.2 KB
/
run_old.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
const newSuite = require("./suite");
const pbjs = require('protobufjs');
var typesJson = require('./tests/simple1/types.json');
var root = pbjs.Root.fromJSON(typesJson);
var pbjsTestReflect = root.resolveAll().lookup("Test");
var pbjsTestStatic = require('./tests/simple1/pbjsStatic').Test;
const jspbTestOptimized = require('./tests/simple1/jspbTestOptimized');
const jspbTestUnoptimized = require('./tests/simple1/types_pb').Test;
const data = require('./tests/simple1/data');
console.log('Payload size (byte):');
console.log('\t Binary:', data.binaryU8.byteLength);
console.log('\t Base64:', Math.ceil(data.binaryU8.byteLength / 3 * 4));
console.log('\tJspb-Text:', data.jspbText.length);
console.log('\t JSON:', data.pbjsJsonStr.length);
console.log();
newSuite("decoding")
// google-protobuf-js does not work with Buffer
.add("google-binary-optimized", function() {
jspbTestOptimized.deserializeBinaryTest(data.binaryU8);
})
.add("google-binary-unoptimized", function() {
jspbTestUnoptimized.deserializeBinary(data.binaryU8);
})
.add("google-text-optimized", function() {
jspbTestOptimized.deserializeTextTest(data.jspbText);
})
.add("protobuf.js-reflect", function() {
pbjsTestReflect.decode(data.binaryBuf);
})
// About 18% slower than "protobuf.js-reflect" in Node
.add("protobuf.js-reflect-Uint8Array", function() {
pbjsTestReflect.decode(data.binaryU8);
})
.add("protobuf.js-static", function() {
pbjsTestStatic.decode(data.binaryBuf);
})
.add("JSON-string", function() {
JSON.parse(data.pbjsJsonStr);
})
.run();
newSuite("encoding")
.add("google-binary-optimized", function() {
jspbTestOptimized.serializeBinaryTest(data.jspbMsgOptimized);
})
.add("google-binary-unoptimized", function() {
data.jspbMsgUnoptimized.serializeBinary();
})
.add("google-text-optimized", function() {
jspbTestOptimized.serializeTextTest(data.jspbMsgOptimized);
})
.add("protobuf.js-reflect", function() {
pbjsTestReflect.encode(data.pbjsMsg).finish();
})
.add("protobuf.js-static", function() {
pbjsTestStatic.encode(data.pbjsMsg).finish();
})
.add("JSON-string", function() {
JSON.stringify(data.pbjsJson);
})
.run();