ADD: added new version of protobuf

This commit is contained in:
Henry Winkel
2022-12-20 10:09:28 +01:00
parent 4a79559129
commit 1e2b3dda7b
1513 changed files with 123720 additions and 83381 deletions

View File

@@ -0,0 +1,25 @@
var pbjs = require("./protobuf.js/cli").pbjs
var argv = [];
var protoFiles = [];
var prefix = "";
process.argv.forEach(function(val, index) {
var arg = val;
if (arg.length > 6 && arg.substring(arg.length - 6) == ".proto") {
protoFiles.push(arg);
} else if (arg.length > 15 && arg.substring(0, 15) == "--include_path=") {
prefix = arg.substring(15);
} else if (index >= 2) {
argv.push(arg);
}
});
protoFiles.forEach(function(val) {
argv.push(prefix + "/" + val);
});
pbjs.main(argv, function(err, output){
if (err) {
console.log(err);
}
});

View File

@@ -0,0 +1,66 @@
var root = require("./generated_bundle_code.js");
var fs = require('fs');
var benchmark = require("./node_modules/benchmark");
var benchmarkSuite = require("./benchmark_suite.js");
function getNewPrototype(name) {
var message = eval("root." + name);
if (typeof(message) == "undefined") {
throw "type " + name + " is undefined";
}
return message;
}
var results = [];
console.log("#####################################################");
console.log("ProtobufJs Benchmark: ");
process.argv.forEach(function(filename, index) {
if (index < 2) {
return;
}
var benchmarkDataset =
root.benchmarks.BenchmarkDataset.decode(fs.readFileSync(filename));
var messageList = [];
var totalBytes = 0;
benchmarkDataset.payload.forEach(function(onePayload) {
var message = getNewPrototype(benchmarkDataset.messageName);
messageList.push(message.decode(onePayload));
totalBytes += onePayload.length;
});
var scenarios = benchmarkSuite.newBenchmark(
benchmarkDataset.messageName, filename, "protobufjs");
scenarios.suite
.add("protobuf.js static decoding", function() {
benchmarkDataset.payload.forEach(function(onePayload) {
var protoType = getNewPrototype(benchmarkDataset.messageName);
protoType.decode(onePayload);
});
})
.add("protobuf.js static encoding", function() {
var protoType = getNewPrototype(benchmarkDataset.messageName);
messageList.forEach(function(message) {
protoType.encode(message).finish();
});
})
.run({"Async": false});
results.push({
filename: filename,
benchmarks: {
protobufjs_decoding: scenarios.benches[0] * totalBytes,
protobufjs_encoding: scenarios.benches[1] * totalBytes
}
})
console.log("Throughput for decoding: "
+ scenarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" );
console.log("Throughput for encoding: "
+ scenarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" );
console.log("");
});
console.log("#####################################################");