mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
Merge pull request #264 from rom1504/mocha_benchmarks
use mocha for benchmark (allow better mocha grepping + it's cleaner)
This commit is contained in:
commit
5593c69416
1 changed files with 32 additions and 20 deletions
|
@ -1,8 +1,8 @@
|
|||
var ITERATIONS = 100000;
|
||||
|
||||
var mc = require("../");
|
||||
util = require('util'),
|
||||
states = mc.states;
|
||||
var util = require('util');
|
||||
var states = mc.states;
|
||||
|
||||
var testDataWrite = [
|
||||
{name: 'keep_alive', params: {keepAliveId: 957759560}},
|
||||
|
@ -12,23 +12,35 @@ var testDataWrite = [
|
|||
];
|
||||
|
||||
mc.supportedVersions.forEach(function(supportedVersion){
|
||||
var inputData = [];
|
||||
var serializer=new mc.createSerializer({state:states.PLAY,isServer:false,version:supportedVersion});
|
||||
var start, i, j;
|
||||
console.log('Beginning write test for '+supportedVersion);
|
||||
start = Date.now();
|
||||
for(i = 0; i < ITERATIONS; i++) {
|
||||
for(j = 0; j < testDataWrite.length; j++) {
|
||||
inputData.push(serializer.createPacketBuffer(testDataWrite[j].name, testDataWrite[j].params));
|
||||
}
|
||||
}
|
||||
console.log('Finished write test in ' + (Date.now() - start) / 1000 + ' seconds');
|
||||
var mcData=require("minecraft-data")(supportedVersion);
|
||||
var version=mcData.version;
|
||||
describe("benchmark "+version.minecraftVersion,function(){
|
||||
this.timeout(20 * 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].name, testDataWrite[j].params));
|
||||
}
|
||||
}
|
||||
var result=(Date.now() - start) / 1000;
|
||||
console.log('Finished write test in ' + result + ' seconds');
|
||||
done();
|
||||
});
|
||||
|
||||
var deserializer=new mc.createDeserializer({state:states.PLAY,isServer:true,version:supportedVersion});
|
||||
console.log('Beginning read test for '+supportedVersion);
|
||||
start = Date.now();
|
||||
for (j = 0; j < inputData.length; j++) {
|
||||
deserializer.parsePacketData(inputData[j]);
|
||||
}
|
||||
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|
||||
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.parsePacketData(inputData[j]);
|
||||
}
|
||||
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue