2015-10-02 20:14:01 -04:00
|
|
|
var ITERATIONS = 10000;
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2015-05-22 21:31:47 -04:00
|
|
|
var mc = require("../");
|
2015-09-30 12:11:57 -04:00
|
|
|
var util = require('util');
|
|
|
|
var states = mc.states;
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2013-12-30 10:05:22 -05:00
|
|
|
var testDataWrite = [
|
2015-09-12 12:56:36 -04:00
|
|
|
{name: 'keep_alive', params: {keepAliveId: 957759560}},
|
|
|
|
{name: 'chat', params: {message: '<Bob> Hello World!'}},
|
2015-11-30 16:19:56 -05:00
|
|
|
{name: 'position_look', params: {x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, onGround: true}}
|
2013-03-16 02:13:05 -04:00
|
|
|
// TODO: add more packets for better quality data
|
|
|
|
];
|
|
|
|
|
2015-09-29 16:41:41 -04:00
|
|
|
mc.supportedVersions.forEach(function(supportedVersion){
|
2015-09-30 12:11:57 -04:00
|
|
|
var mcData=require("minecraft-data")(supportedVersion);
|
|
|
|
var version=mcData.version;
|
|
|
|
describe("benchmark "+version.minecraftVersion,function(){
|
2015-10-02 20:14:01 -04:00
|
|
|
this.timeout(60 * 1000);
|
2015-09-30 12:11:57 -04:00
|
|
|
var inputData = [];
|
|
|
|
it("bench serializing",function(done){
|
2016-02-18 19:02:57 -05:00
|
|
|
var serializer=new mc.createSerializer({state:states.PLAY,isServer:false,version:version.minecraftVersion});
|
2015-09-30 12:11:57 -04:00
|
|
|
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++) {
|
2015-10-02 20:14:01 -04:00
|
|
|
inputData.push(serializer.createPacketBuffer(testDataWrite[j]));
|
2015-09-30 12:11:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var result=(Date.now() - start) / 1000;
|
|
|
|
console.log('Finished write test in ' + result + ' seconds');
|
|
|
|
done();
|
|
|
|
});
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2015-09-30 12:11:57 -04:00
|
|
|
it("bench parsing",function(done){
|
2016-02-18 19:02:57 -05:00
|
|
|
var deserializer=new mc.createDeserializer({state:states.PLAY,isServer:true,version:version.minecraftVersion});
|
2015-09-30 12:11:57 -04:00
|
|
|
console.log('Beginning read test');
|
|
|
|
start = Date.now();
|
2015-11-30 16:19:56 -05:00
|
|
|
for (var j = 0; j < inputData.length; j++) {
|
2015-10-02 20:14:01 -04:00
|
|
|
deserializer.parsePacketBuffer(inputData[j]);
|
2015-09-30 12:11:57 -04:00
|
|
|
}
|
|
|
|
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-09-29 16:41:41 -04:00
|
|
|
});
|