mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
f45c6dff49
* move general datatypes to protodef along with their tests * move states to states.js file * use one protodef serializer by state and direction instead of one big serializer for everything (same thing for the deserializer) * define a packet as a protodef type using a switch and a container, and adding each minecraft packet as a type (packet_ + name) * use mapper type from protodef to convert id to name in packet definition * use general string type : pstring * divide by 10 the number of iteration in the benchmark to get back to a reasonable test execution time
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
var ITERATIONS = 10000;
|
|
|
|
var mc = require("../");
|
|
var util = require('util');
|
|
var states = mc.states;
|
|
|
|
var testDataWrite = [
|
|
{name: 'keep_alive', params: {keepAliveId: 957759560}},
|
|
{name: 'chat', params: {message: '<Bob> Hello World!'}},
|
|
{name: 'position_look', params: {x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, onGround: true}},
|
|
// TODO: add more packets for better quality data
|
|
];
|
|
|
|
mc.supportedVersions.forEach(function(supportedVersion){
|
|
var mcData=require("minecraft-data")(supportedVersion);
|
|
var version=mcData.version;
|
|
describe("benchmark "+version.minecraftVersion,function(){
|
|
this.timeout(60 * 1000);
|
|
var inputData = [];
|
|
it("bench serializing",function(done){
|
|
var serializer=new mc.createSerializer({state:states.PLAY,isServer:false,version:version.majorVersion});
|
|
var start, i, j;
|
|
console.log('Beginning write test');
|
|
start = Date.now();
|
|
for(i = 0; i < ITERATIONS; i++) {
|
|
for(j = 0; j < testDataWrite.length; j++) {
|
|
inputData.push(serializer.createPacketBuffer(testDataWrite[j]));
|
|
}
|
|
}
|
|
var result=(Date.now() - start) / 1000;
|
|
console.log('Finished write test in ' + result + ' seconds');
|
|
done();
|
|
});
|
|
|
|
it("bench parsing",function(done){
|
|
var deserializer=new mc.createDeserializer({state:states.PLAY,isServer:true,version:version.majorVersion});
|
|
console.log('Beginning read test');
|
|
start = Date.now();
|
|
for (j = 0; j < inputData.length; j++) {
|
|
deserializer.parsePacketBuffer(inputData[j]);
|
|
}
|
|
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|
|
done();
|
|
});
|
|
});
|
|
});
|