Page MenuHomeSealhub

perf.test.tsx
No OneTemporary

perf.test.tsx

import assert from "node:assert";
import { TempstreamJSX, tempstream } from "../src/index";
import { sleep } from "./sleep";
describe("performance", () => {
it("handles a 300kb string-only document in less than 150% of the time it would take for a string-based approach", async () => {
const array = [];
for (let i = 0; i < 180000; i++) {
array.push(Math.random());
}
const time = Date.now();
const stream = (
<body>
{array.map(async (number) => {
await sleep(0);
return number.toString();
})}
</body>
);
const string = await stream;
const stream_time = Date.now() - time;
const time_str = Date.now();
const string2 = `
<body>
${(
await Promise.all(
array.map(async (number) => {
await sleep(0);
return number.toString();
})
)
).join("")}
</body>
`;
const string_time = Date.now() - time_str;
console.log({ stream_time, string_time });
assert(stream_time < string_time * 1.5);
});
it("handles a 300kb Promise<Stream>-filled document in less than 300% of the time it would take for a string-based approach", async () => {
const array = [];
for (let i = 0; i < 180000; i++) {
array.push(Math.random());
}
const time = Date.now();
const stream = (
<body>
{array.map(async (number) => {
await sleep(0);
return tempstream`${number.toString()}`;
})}
</body>
);
await stream;
const stream_time = Date.now() - time;
const time_str = Date.now();
`
<body>
${(
await Promise.all(
array.map(async (number) => {
await sleep(0);
return number.toString();
})
)
).join("")}
</body>
`;
const string_time = Date.now() - time_str;
console.log({ stream_time, string_time });
assert(stream_time < string_time * 3);
});
});

File Metadata

Mime Type
text/x-java
Expires
Sat, Nov 8, 02:46 (18 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1033951
Default Alt Text
perf.test.tsx (1 KB)

Event Timeline