Struct: speed test
This commit is contained in:
@ -64,15 +64,33 @@ describe(Struct.name, () => {
|
|||||||
0x00, 0x00, 0x00, 0x05, // user.name.size
|
0x00, 0x00, 0x00, 0x05, // user.name.size
|
||||||
0x68, 0x65, 0x6C, 0x6C, 0x6F, // user.name.data
|
0x68, 0x65, 0x6C, 0x6C, 0x6F, // user.name.data
|
||||||
])
|
])
|
||||||
|
let nested_json
|
||||||
|
|
||||||
test('serialize, nested', () => {
|
test('serialize, nested', () => {
|
||||||
|
let start = process.hrtime.bigint()
|
||||||
const dv = sizedDataView(sizeof(nested, Nested))
|
const dv = sizedDataView(sizeof(nested, Nested))
|
||||||
serialize(dv, 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)
|
expectDataViewEqual(dv, nested_dv)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parse, nested', () => {
|
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({
|
const Token = Struct({
|
||||||
|
|||||||
Reference in New Issue
Block a user