2018-05-13 16:50:16 -04:00
|
|
|
/* eslint-env mocha */
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
const ITERATIONS = 10000
|
|
|
|
|
|
|
|
const mc = require('../')
|
|
|
|
const states = mc.states
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2017-07-13 08:03:52 -04:00
|
|
|
const testDataWrite = [
|
2018-09-24 16:07:34 -04:00
|
|
|
{ name: 'keep_alive', params: { keepAliveId: 957759560 } },
|
2022-08-15 18:57:26 -04:00
|
|
|
// TODO: 1.19+ `chat` -> `player_chat` feature toggle
|
|
|
|
// { name: 'chat', params: { message: '<Bob> Hello World!' } },
|
2018-09-24 16:07:34 -04: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
|
2018-05-13 16:50:16 -04:00
|
|
|
]
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2021-06-12 22:54:16 -04:00
|
|
|
for (const supportedVersion of mc.supportedVersions) {
|
2018-05-13 16:50:16 -04:00
|
|
|
const mcData = require('minecraft-data')(supportedVersion)
|
|
|
|
const version = mcData.version
|
2023-12-27 18:12:23 -05:00
|
|
|
describe('benchmark ' + supportedVersion + 'v', function () {
|
2018-05-13 16:50:16 -04:00
|
|
|
this.timeout(60 * 1000)
|
|
|
|
const inputData = []
|
|
|
|
it('bench serializing', function (done) {
|
2018-09-24 16:07:34 -04:00
|
|
|
const serializer = mc.createSerializer({ state: states.PLAY, isServer: false, version: version.minecraftVersion })
|
2019-08-03 19:29:14 -04:00
|
|
|
let i, j
|
2018-05-13 16:50:16 -04:00
|
|
|
console.log('Beginning write test')
|
2019-08-03 19:29:14 -04:00
|
|
|
const start = Date.now()
|
2018-05-13 16:50:16 -04:00
|
|
|
for (i = 0; i < ITERATIONS; i++) {
|
|
|
|
for (j = 0; j < testDataWrite.length; j++) {
|
|
|
|
inputData.push(serializer.createPacketBuffer(testDataWrite[j]))
|
2015-09-30 12:11:57 -04:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 16:50:16 -04:00
|
|
|
const result = (Date.now() - start) / 1000
|
|
|
|
console.log('Finished write test in ' + result + ' seconds')
|
|
|
|
done()
|
|
|
|
})
|
2013-03-16 02:13:05 -04:00
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
it('bench parsing', function (done) {
|
2018-09-24 16:07:34 -04:00
|
|
|
const deserializer = mc.createDeserializer({ state: states.PLAY, isServer: true, version: version.minecraftVersion })
|
2018-05-13 16:50:16 -04:00
|
|
|
console.log('Beginning read test')
|
|
|
|
const start = Date.now()
|
2017-07-13 08:03:52 -04:00
|
|
|
for (let j = 0; j < inputData.length; j++) {
|
2018-05-13 16:50:16 -04:00
|
|
|
deserializer.parsePacketBuffer(inputData[j])
|
2015-09-30 12:11:57 -04:00
|
|
|
}
|
2018-05-13 16:50:16 -04:00
|
|
|
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2021-06-12 22:54:16 -04:00
|
|
|
}
|