From 622e5eef7d78940fafe81f91de76dc82578b6023 Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Sun, 10 Aug 2025 09:42:06 +0300 Subject: [PATCH] Struct: speed test --- test/Struct.test.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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({