Skip to content

Commit cb92b16

Browse files
Add benchmarks covering resolveAll
1 parent 1dbcfe3 commit cb92b16

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

bench/index.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
// in between.
1111

1212
var newSuite = require("./suite"),
13-
payload = require("./data/bench.json");
13+
payload = require("./data/bench.json"),
14+
protobuf = require("..");
1415

1516
var Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from || function(value, encoding) { return new Buffer(value, encoding); };
1617

@@ -88,3 +89,41 @@ newSuite("combined")
8889
jspbCls.deserializeBinary(jspbMsg.serializeBinary());
8990
})
9091
.run();
92+
93+
var json = require("../tests/data/test.json");
94+
var fromJsonRoot = protobuf.Root.fromJSON(json);
95+
var fromJsonIndex = 1;
96+
97+
newSuite("fromJSON")
98+
.add("isolated", function() {
99+
protobuf.Root.fromJSON(json);
100+
})
101+
.add("isolated (resolveAll)", function() {
102+
protobuf.Root.fromJSON(json).resolveAll();
103+
})
104+
.add("shared (unique)", function() {
105+
var jsonCopy = {
106+
options: json.options,
107+
nested: {}
108+
};
109+
Object.keys(json).forEach(key => {
110+
jsonCopy.nested[key + fromJsonIndex] = json[key]
111+
});
112+
fromJsonIndex++;
113+
114+
protobuf.Root.fromJSON(jsonCopy, fromJsonRoot);
115+
}).run();
116+
117+
var resolveAllRoot = protobuf.Root.fromJSON(json);
118+
119+
newSuite("resolveAll")
120+
.add("isolated", function() {
121+
resolveAllRoot.resolveAll();
122+
}).run();
123+
124+
newSuite("load")
125+
.add("sync", function() {
126+
protobuf.loadSync("bench/data/bench.proto");
127+
})
128+
.run()
129+

0 commit comments

Comments
 (0)