Skip to content

Commit 114920c

Browse files
authored
test(core/protocols): add json rpc perf baseline (#7505)
1 parent 674fae6 commit 114920c

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

packages/core/src/submodules/protocols/json/AwsJson1_1Protocol.spec.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpResponse } from "@smithy/protocol-http";
22
import { describe, expect, test as it } from "vitest";
33

4-
import { context, deleteObjects } from "../test-schema.spec";
4+
import { context, createNestingWidget, deleteObjects, nestingWidget } from "../test-schema.spec";
55
import { AwsJson1_1Protocol } from "./AwsJson1_1Protocol";
66

77
/**
@@ -122,4 +122,55 @@ describe(AwsJson1_1Protocol, () => {
122122
},
123123
});
124124
});
125+
126+
describe("performance baseline", () => {
127+
const protocol = new AwsJson1_1Protocol({
128+
defaultNamespace: "",
129+
serviceTarget: "JsonRpc11",
130+
});
131+
132+
it("should serialize objects", async () => {
133+
const timings: string[] = [];
134+
const objects = [];
135+
136+
for (let i = 0; i < 12; ++i) {
137+
const o = createNestingWidget(2 ** i);
138+
objects.push(o);
139+
}
140+
141+
for (let i = 0; i < objects.length; ++i) {
142+
const o = objects[i];
143+
144+
const A = performance.now();
145+
const request = await protocol.serializeRequest(
146+
{
147+
input: nestingWidget,
148+
output: "unit",
149+
traits: 0,
150+
namespace: "operation",
151+
name: "ns",
152+
},
153+
o,
154+
context
155+
);
156+
const B = performance.now();
157+
158+
timings.push(
159+
`${(B - A).toFixed(2)}ms (JSON length = ${request.body.length}, ${
160+
request.body.length / 1024 / (B - A)
161+
} kb/ms)`
162+
);
163+
}
164+
165+
/**
166+
* No assertion here.
167+
* In the initial dual-pass implementation,
168+
* par time is 0 to 30ms for up to 288899 chars of JSON. Up to 11 kb/ms. (kuhe's computer)
169+
*
170+
* In the single-pass implementation using string buildup,
171+
* par time is 0 to 51ms for up to 288899 chars of JSON. Up to 13 kb/ms. (kuhe's computer)
172+
*/
173+
console.log(`${protocol.constructor.name} performance timings`, timings);
174+
});
175+
});
125176
});

0 commit comments

Comments
 (0)