mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-18 11:32:35 -05:00
2224d82406
* support 1.21.3 * Add bitflags, registryEntryHolder and registryEntryHolderSet types * Fix spacing in compiler types * Update compiler-minecraft.js * Fix registryEntryHolderSet read code (#1351) * Update ci.yml * Fix test for 1.21.3 (#1353) * Remove debug logging * Fix benchmark tests for 1.21.3 * Start updating packetTest for 1.21.3 * Update packetTest.js with new types * Fix minecraft-compiler * Speedup tests by setting world type to flat and disabling structures. * Didn't mean to commit that --------- Co-authored-by: extremeheat <extreme@protonmail.ch> Co-authored-by: Grooble <grooble.dierne@gmail.com>
49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
/* eslint-env mocha */
|
|
|
|
const ITERATIONS = 10000
|
|
|
|
const mc = require('../')
|
|
const states = mc.states
|
|
|
|
for (const supportedVersion of mc.supportedVersions) {
|
|
const mcData = require('minecraft-data')(supportedVersion)
|
|
const version = mcData.version
|
|
const positionFlags = mcData.isNewerOrEqualTo('1.21.3') ? { flags: { onGround: true, hasHorizontalCollision: false } } : { onGround: true }
|
|
const testDataWrite = [
|
|
{ name: 'keep_alive', params: { keepAliveId: 957759560 } },
|
|
// TODO: 1.19+ `chat` -> `player_chat` feature toggle
|
|
// { 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, ...positionFlags } }
|
|
// TODO: add more packets for better quality data
|
|
]
|
|
|
|
describe('benchmark ' + supportedVersion + 'v', function () {
|
|
this.timeout(60 * 1000)
|
|
const inputData = []
|
|
it('bench serializing', function (done) {
|
|
const serializer = mc.createSerializer({ state: states.PLAY, isServer: false, version: version.minecraftVersion })
|
|
let i, j
|
|
console.log('Beginning write test')
|
|
const start = Date.now()
|
|
for (i = 0; i < ITERATIONS; i++) {
|
|
for (j = 0; j < testDataWrite.length; j++) {
|
|
inputData.push(serializer.createPacketBuffer(testDataWrite[j]))
|
|
}
|
|
}
|
|
const result = (Date.now() - start) / 1000
|
|
console.log('Finished write test in ' + result + ' seconds')
|
|
done()
|
|
})
|
|
|
|
it('bench parsing', function (done) {
|
|
const deserializer = mc.createDeserializer({ state: states.PLAY, isServer: true, version: version.minecraftVersion })
|
|
console.log('Beginning read test')
|
|
const start = Date.now()
|
|
for (let j = 0; j < inputData.length; j++) {
|
|
deserializer.parsePacketBuffer(inputData[j])
|
|
}
|
|
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds')
|
|
done()
|
|
})
|
|
})
|
|
}
|