35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { readSpreadsheet } from "@/infra/spreadsheet/parse";
|
|
import { buildCsv, buildXlsx } from "@/infra/export/tabular";
|
|
|
|
function csv(rows: number): Buffer {
|
|
const lines = ["Nome,Valor"];
|
|
for (let index = 0; index < rows; index += 1) lines.push(`Pessoa ${index},${index}`);
|
|
return Buffer.from(lines.join("\n"), "utf8");
|
|
}
|
|
|
|
async function measure(rows: number) {
|
|
const bytes = csv(rows);
|
|
const started = performance.now();
|
|
const parsed = await readSpreadsheet("amostra.csv", bytes);
|
|
const readMs = performance.now() - started;
|
|
const writeStarted = performance.now();
|
|
buildCsv(parsed.grid.headers, parsed.grid.rows);
|
|
const csvMs = performance.now() - writeStarted;
|
|
const xlsxStarted = performance.now();
|
|
await buildXlsx(parsed.grid.headers, parsed.grid.rows);
|
|
const xlsxMs = performance.now() - xlsxStarted;
|
|
return { rows, readMs, csvMs, xlsxMs, heapMb: Math.round(process.memoryUsage().heapUsed / 1024 / 1024) };
|
|
}
|
|
|
|
describe("baseline de planilha", () => {
|
|
it("mede leitura e escrita em amostra pequena e média", async () => {
|
|
const small = await measure(200);
|
|
const medium = await measure(5_000);
|
|
expect(small.readMs).toBeLessThan(5_000);
|
|
expect(medium.readMs).toBeLessThan(15_000);
|
|
expect(medium.xlsxMs).toBeLessThan(30_000);
|
|
expect(small.rows).toBe(200);
|
|
});
|
|
});
|