Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9e4b5fa4a | ||
|
|
7ca5f2d8a0 | ||
|
|
555877b438 | ||
|
|
f9ce32b474 | ||
|
|
afcf3afea1 |
@@ -629,23 +629,34 @@ describe("results of methods on an escaped receiver", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("expands a receiver's methods once rather than once per call (#1495)", () => {
|
it("expands a receiver's methods once rather than once per call (#1495)", () => {
|
||||||
const count = 2000;
|
const receiverCalls = (count: number) => {
|
||||||
const methods = Array.from(
|
const methods = Array.from(
|
||||||
{ length: count },
|
{ length: count },
|
||||||
(_, index) => `m${index}() { return shared; },`,
|
(_, index) => `m${index}() { return shared; },`,
|
||||||
).join(" ");
|
).join(" ");
|
||||||
const calls = Array.from(
|
const calls = Array.from(
|
||||||
{ length: count },
|
{ length: count },
|
||||||
(_, index) => `box.m${index}().p${index} = ${index};`,
|
(_, index) => `box.m${index}().p${index} = ${index};`,
|
||||||
).join(" ");
|
).join(" ");
|
||||||
const start = performance.now();
|
return `const shared = { token: "TOKEN" }; const box = { ${methods} }; ${calls} return [shared.token];`;
|
||||||
const value = resultValue(
|
};
|
||||||
`const shared = { token: "TOKEN" }; const box = { ${methods} }; ${calls} return [shared.token];`,
|
const fastest = (body: string) =>
|
||||||
);
|
Math.min(
|
||||||
expect(performance.now() - start).toBeLessThan(2000);
|
...[0, 1].map(() => {
|
||||||
expect(value).toMatchObject({
|
const start = performance.now();
|
||||||
|
resultValue(body);
|
||||||
|
return performance.now() - start;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
resultValue(receiverCalls(100));
|
||||||
|
// Compare growth rather than wall time, which depends on the runner and on
|
||||||
|
// coverage instrumentation. Four times the calls costs about 5-6x here;
|
||||||
|
// re-expanding every method per call cost about 13-14x.
|
||||||
|
const ratio = fastest(receiverCalls(1600)) / fastest(receiverCalls(400));
|
||||||
|
expect(ratio).toBeLessThan(10);
|
||||||
|
expect(resultValue(receiverCalls(400))).toMatchObject({
|
||||||
status: "array",
|
status: "array",
|
||||||
items: [{ value: { status: "unknown" } }],
|
items: [{ value: { status: "unknown" } }],
|
||||||
});
|
});
|
||||||
}, 30000);
|
}, 60000);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user