diff --git a/test/Struct.test.js b/test/Struct.test.js index 761a5fb..3019285 100644 --- a/test/Struct.test.js +++ b/test/Struct.test.js @@ -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({