Struct: speed test

This commit is contained in:
2025-08-10 09:42:06 +03:00
parent e2f2c03433
commit 622e5eef7d

View File

@ -64,15 +64,33 @@ describe(Struct.name, () => {
0x00, 0x00, 0x00, 0x05, // user.name.size
0x68, 0x65, 0x6C, 0x6C, 0x6F, // user.name.data
])
let nested_json
test('serialize, nested', () => {
let start = process.hrtime.bigint()
const dv = sizedDataView(sizeof(nested, Nested))
serialize(dv, nested, Nested)
const delta_serialize = process.hrtime.bigint() - start
start = process.hrtime.bigint()
nested_json = JSON.stringify(nested)
const delta_json = process.hrtime.bigint() - start
console.log(`Struct, nested: serialize ns: ${delta_serialize}, JSON.stringify ns: ${delta_json}`)
expectDataViewEqual(dv, nested_dv)
})
test('parse, nested', () => {
expectDataViewEqual(parse(nested_dv, Nested), nested)
let start = process.hrtime.bigint()
const actual = parse(nested_dv, Nested)
const delta_serialize = process.hrtime.bigint() - start
start = process.hrtime.bigint()
const json = JSON.parse(nested_json)
const delta_json = process.hrtime.bigint() - start
console.log(`Struct, nested: parse ns: ${delta_serialize}, JSON.parse ns: ${delta_json}`)
expectDataViewEqual(actual, nested)
})
const Token = Struct({