|
1 | 1 | import { HttpResponse } from "@smithy/protocol-http"; |
2 | 2 | import { describe, expect, test as it } from "vitest"; |
3 | 3 |
|
4 | | -import { context, deleteObjects } from "../test-schema.spec"; |
| 4 | +import { context, createNestingWidget, deleteObjects, nestingWidget } from "../test-schema.spec"; |
5 | 5 | import { AwsJson1_1Protocol } from "./AwsJson1_1Protocol"; |
6 | 6 |
|
7 | 7 | /** |
@@ -122,4 +122,55 @@ describe(AwsJson1_1Protocol, () => { |
122 | 122 | }, |
123 | 123 | }); |
124 | 124 | }); |
| 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 | + }); |
125 | 176 | }); |
0 commit comments