2014-01-02 19:58:09 -05:00
|
|
|
var ITERATIONS = 100000;
|
2013-03-16 02:13:05 -04:00
|
|
|
|
|
|
|
var Client = require('../lib/client'),
|
|
|
|
EventEmitter = require('events').EventEmitter,
|
2013-12-30 10:05:22 -05:00
|
|
|
util = require('util'),
|
|
|
|
states = require('../lib/protocol').states;
|
2013-03-16 02:13:05 -04:00
|
|
|
|
|
|
|
var FakeSocket = function() {
|
|
|
|
EventEmitter.call(this);
|
|
|
|
};
|
|
|
|
util.inherits(FakeSocket, EventEmitter);
|
2013-11-19 18:06:57 -05:00
|
|
|
FakeSocket.prototype.write = function(){};
|
2013-03-16 02:13:05 -04:00
|
|
|
|
|
|
|
var client = new Client();
|
|
|
|
var socket = new FakeSocket();
|
|
|
|
client.setSocket(socket);
|
2013-12-30 10:05:22 -05:00
|
|
|
client.state = states.PLAY;
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2013-12-30 10:05:22 -05:00
|
|
|
var testDataWrite = [
|
|
|
|
{id: 0x00, params: {keepAliveId: 957759560}},
|
|
|
|
{id: 0x01, params: {message: '<Bob> Hello World!'}},
|
|
|
|
{id: 0x06, 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
|
|
|
|
];
|
|
|
|
|
|
|
|
var start, i, j;
|
|
|
|
console.log('Beginning write test');
|
|
|
|
start = Date.now();
|
|
|
|
for(i = 0; i < ITERATIONS; i++) {
|
2013-12-30 10:05:22 -05:00
|
|
|
for(j = 0; j < testDataWrite.length; j++) {
|
|
|
|
client.write(testDataWrite[j].id, testDataWrite[j].params);
|
2013-03-16 02:13:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('Finished write test in ' + (Date.now() - start) / 1000 + ' seconds');
|
|
|
|
|
2013-12-30 10:05:22 -05:00
|
|
|
var testDataRead = [
|
|
|
|
{id: 0x00, params: {keepAliveId: 957759560}},
|
|
|
|
{id: 0x02, params: {message: '<Bob> Hello World!'}},
|
|
|
|
{id: 0x08, params: {x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, onGround: true}},
|
|
|
|
];
|
|
|
|
|
|
|
|
client.isServer = true;
|
|
|
|
|
2013-03-16 02:13:05 -04:00
|
|
|
var inputData = new Buffer(0);
|
|
|
|
socket.write = function(data) {
|
|
|
|
inputData = Buffer.concat([inputData, data]);
|
|
|
|
};
|
2013-12-30 10:05:22 -05:00
|
|
|
for(i = 0; i < testDataRead.length; i++) {
|
|
|
|
client.write(testDataRead[i].id, testDataRead[i].params);
|
2013-03-16 02:13:05 -04:00
|
|
|
}
|
|
|
|
|
2013-12-30 10:05:22 -05:00
|
|
|
client.isServer = false;
|
|
|
|
|
2013-03-16 02:13:05 -04:00
|
|
|
console.log('Beginning read test');
|
|
|
|
start = Date.now();
|
|
|
|
for(i = 0; i < ITERATIONS; i++) {
|
|
|
|
socket.emit('data', inputData);
|
|
|
|
}
|
|
|
|
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds');
|