parent
88795f64e4
commit
a7071291c7
6 changed files with 263 additions and 2 deletions
@ -0,0 +1,33 @@ |
|||||||
|
var benchmark = require("./node_modules/benchmark"); |
||||||
|
|
||||||
|
function newBenchmark(messageName, filename, language) { |
||||||
|
var benches = []; |
||||||
|
return { |
||||||
|
suite: new benchmark.Suite(messageName + filename + language ) |
||||||
|
.on("add", function(event) { |
||||||
|
benches.push(event.target); |
||||||
|
}) |
||||||
|
.on("start", function() { |
||||||
|
process.stdout.write( |
||||||
|
"benchmarking message " + messageName
|
||||||
|
+ " of dataset file " + filename
|
||||||
|
+ "'s performance ..." + "\n\n"); |
||||||
|
}) |
||||||
|
.on("cycle", function(event) { |
||||||
|
process.stdout.write(String(event.target) + "\n"); |
||||||
|
}) |
||||||
|
.on("complete", function() { |
||||||
|
var getHz = function(bench) { |
||||||
|
return 1 / (bench.stats.mean + bench.stats.moe); |
||||||
|
} |
||||||
|
benches.forEach(function(val, index) { |
||||||
|
benches[index] = getHz(val);
|
||||||
|
}); |
||||||
|
}), |
||||||
|
benches: benches |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
newBenchmark: newBenchmark |
||||||
|
} |
@ -0,0 +1,69 @@ |
|||||||
|
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'); |
||||||
|
var benchmarkSuite = require("./BenchmarkSuite.js"); |
||||||
|
|
||||||
|
|
||||||
|
function getNewPrototype(name) { |
||||||
|
var message = eval("proto." + name); |
||||||
|
if (typeof(message) == "undefined") { |
||||||
|
throw "type " + name + " is undefined"; |
||||||
|
} |
||||||
|
return message; |
||||||
|
} |
||||||
|
|
||||||
|
var results = []; |
||||||
|
|
||||||
|
console.log("#####################################################"); |
||||||
|
console.log("Js Benchmark: "); |
||||||
|
process.argv.forEach(function(filename, index) { |
||||||
|
if (index < 2) { |
||||||
|
return; |
||||||
|
} |
||||||
|
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; |
||||||
|
}); |
||||||
|
|
||||||
|
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); |
||||||
|
});
|
||||||
|
}) |
||||||
|
.add("js serialize", function() { |
||||||
|
var protoType = getNewPrototype(benchmarkDataset.getMessageName()); |
||||||
|
messageList.forEach(function(message) { |
||||||
|
message.serializeBinary(); |
||||||
|
}); |
||||||
|
})
|
||||||
|
.run({"Async": false}); |
||||||
|
|
||||||
|
results.push({ |
||||||
|
filename: filename, |
||||||
|
benchmarks: { |
||||||
|
protobufjs_decoding: senarios.benches[0] * totalBytes, |
||||||
|
protobufjs_encoding: senarios.benches[1] * totalBytes |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
console.log("Throughput for deserialize: "
|
||||||
|
+ senarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" ); |
||||||
|
console.log("Throughput for serialize: "
|
||||||
|
+ senarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" ); |
||||||
|
console.log(""); |
||||||
|
}); |
||||||
|
console.log("#####################################################"); |
@ -0,0 +1,24 @@ |
|||||||
|
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); |
||||||
|
} |
||||||
|
}); |
@ -0,0 +1,65 @@ |
|||||||
|
var root = require("./GeneratedBundleCode.js"); |
||||||
|
var fs = require('fs'); |
||||||
|
var benchmark = require("./node_modules/benchmark"); |
||||||
|
var benchmarkSuite = require("./BenchmarkSuite.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 senarios = benchmarkSuite.newBenchmark( |
||||||
|
benchmarkDataset.messageName, filename, "protobufjs"); |
||||||
|
senarios.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: senarios.benches[0] * totalBytes, |
||||||
|
protobufjs_encoding: senarios.benches[1] * totalBytes |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
console.log("Throughput for decoding: "
|
||||||
|
+ senarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" ); |
||||||
|
console.log("Throughput for encoding: "
|
||||||
|
+ senarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" ); |
||||||
|
console.log(""); |
||||||
|
}); |
||||||
|
console.log("#####################################################"); |
Loading…
Reference in new issue