diff --git a/packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.spec.ts b/packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.spec.ts index 1ab24ff49fa8..7714fa4d425e 100644 --- a/packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.spec.ts +++ b/packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.spec.ts @@ -1,7 +1,7 @@ import { HttpResponse } from "@smithy/protocol-http"; import { describe, expect, test as it } from "vitest"; -import { context, deleteObjects } from "../test-schema.spec"; +import { context, createNestingWidget, deleteObjects, nestingWidget } from "../test-schema.spec"; import { AwsJson1_1Protocol } from "./AwsJson1_1Protocol"; /** @@ -122,4 +122,55 @@ describe(AwsJson1_1Protocol, () => { }, }); }); + + describe("performance baseline", () => { + const protocol = new AwsJson1_1Protocol({ + defaultNamespace: "", + serviceTarget: "JsonRpc11", + }); + + it("should serialize objects", async () => { + const timings: string[] = []; + const objects = []; + + for (let i = 0; i < 12; ++i) { + const o = createNestingWidget(2 ** i); + objects.push(o); + } + + for (let i = 0; i < objects.length; ++i) { + const o = objects[i]; + + const A = performance.now(); + const request = await protocol.serializeRequest( + { + input: nestingWidget, + output: "unit", + traits: 0, + namespace: "operation", + name: "ns", + }, + o, + context + ); + const B = performance.now(); + + timings.push( + `${(B - A).toFixed(2)}ms (JSON length = ${request.body.length}, ${ + request.body.length / 1024 / (B - A) + } kb/ms)` + ); + } + + /** + * No assertion here. + * In the initial dual-pass implementation, + * par time is 0 to 30ms for up to 288899 chars of JSON. Up to 11 kb/ms. (kuhe's computer) + * + * In the single-pass implementation using string buildup, + * par time is 0 to 51ms for up to 288899 chars of JSON. Up to 13 kb/ms. (kuhe's computer) + */ + console.log(`${protocol.constructor.name} performance timings`, timings); + }); + }); });