1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-01-05 17:13:36 +08:00
Nicholas Hastings c5d57c03ee
Update Protobuf and add protos for CS2 (#176)
* Replace protobuf 2.6.1 with 3.21.8

* Update/add protobuf libs

* Add CS2 protos

* Remove old csgo/dota protos

* Add versioned protoc bin

* Comment out Valve's `schema` define for now

* Use ENetworkDisconnectionReason

* Fix-up `offsetof` to avoid errors on some Clang versions
2023-11-15 23:58:12 +00:00

67 lines
2.0 KiB
JavaScript

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("#####################################################");