Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -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);
});
});
});
Loading