2018-07-20 23:13:19 +00:00
|
|
|
require('./datasets/google_message1/proto2/benchmark_message1_proto2_pb.js');
|
|
|
|
require('./datasets/google_message1/proto3/benchmark_message1_proto3_pb.js');
|
|
|
|
require('./datasets/google_message2/benchmark_message2_pb.js');
|
|
|
|
require('./datasets/google_message3/benchmark_message3_pb.js');
|
|
|
|
require('./datasets/google_message4/benchmark_message4_pb.js');
|
|
|
|
require('./benchmarks_pb.js');
|
|
|
|
|
|
|
|
var fs = require('fs');
|
2018-08-08 18:24:09 +00:00
|
|
|
var benchmarkSuite = require("./benchmark_suite.js");
|
2018-07-20 23:13:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
function getNewPrototype(name) {
|
|
|
|
var message = eval("proto." + name);
|
|
|
|
if (typeof(message) == "undefined") {
|
|
|
|
throw "type " + name + " is undefined";
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
var results = [];
|
2018-09-25 23:05:16 +00:00
|
|
|
var json_file = "";
|
2018-07-20 23:13:19 +00:00
|
|
|
|
|
|
|
console.log("#####################################################");
|
|
|
|
console.log("Js Benchmark: ");
|
|
|
|
process.argv.forEach(function(filename, index) {
|
|
|
|
if (index < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-25 23:05:16 +00:00
|
|
|
if (filename.indexOf("--json_output") != -1) {
|
|
|
|
json_file = filename.replace(/^--json_output=/, '');
|
|
|
|
return;
|
|
|
|
}
|
2019-02-21 03:28:50 +00:00
|
|
|
|
2018-07-20 23:13:19 +00:00
|
|
|
var benchmarkDataset =
|
|
|
|
proto.benchmarks.BenchmarkDataset.deserializeBinary(fs.readFileSync(filename));
|
|
|
|
var messageList = [];
|
|
|
|
var totalBytes = 0;
|
|
|
|
benchmarkDataset.getPayloadList().forEach(function(onePayload) {
|
|
|
|
var message = getNewPrototype(benchmarkDataset.getMessageName());
|
|
|
|
messageList.push(message.deserializeBinary(onePayload));
|
|
|
|
totalBytes += onePayload.length;
|
|
|
|
});
|
2019-02-21 03:28:50 +00:00
|
|
|
|
2018-07-20 23:13:19 +00:00
|
|
|
var senarios = benchmarkSuite.newBenchmark(
|
|
|
|
benchmarkDataset.getMessageName(), filename, "js");
|
|
|
|
senarios.suite
|
|
|
|
.add("js deserialize", function() {
|
|
|
|
benchmarkDataset.getPayloadList().forEach(function(onePayload) {
|
|
|
|
var protoType = getNewPrototype(benchmarkDataset.getMessageName());
|
|
|
|
protoType.deserializeBinary(onePayload);
|
2019-02-21 03:28:50 +00:00
|
|
|
});
|
2018-07-20 23:13:19 +00:00
|
|
|
})
|
|
|
|
.add("js serialize", function() {
|
|
|
|
var protoType = getNewPrototype(benchmarkDataset.getMessageName());
|
|
|
|
messageList.forEach(function(message) {
|
|
|
|
message.serializeBinary();
|
|
|
|
});
|
2019-02-21 03:28:50 +00:00
|
|
|
})
|
2018-07-20 23:13:19 +00:00
|
|
|
.run({"Async": false});
|
|
|
|
|
|
|
|
results.push({
|
|
|
|
filename: filename,
|
|
|
|
benchmarks: {
|
2018-09-25 23:05:16 +00:00
|
|
|
protobufjs_decoding: senarios.benches[0] * totalBytes / 1024 / 1024,
|
|
|
|
protobufjs_encoding: senarios.benches[1] * totalBytes / 1024 / 1024
|
2018-07-20 23:13:19 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-02-21 03:28:50 +00:00
|
|
|
console.log("Throughput for deserialize: "
|
2018-07-20 23:13:19 +00:00
|
|
|
+ senarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" );
|
2019-02-21 03:28:50 +00:00
|
|
|
console.log("Throughput for serialize: "
|
2018-07-20 23:13:19 +00:00
|
|
|
+ senarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" );
|
|
|
|
console.log("");
|
|
|
|
});
|
2018-08-08 18:24:09 +00:00
|
|
|
console.log("#####################################################");
|
|
|
|
|
2018-09-25 23:05:16 +00:00
|
|
|
if (json_file != "") {
|
|
|
|
fs.writeFile(json_file, JSON.stringify(results), (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|