Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 10 additions & 12 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"pkijs": "^3.4.0"
},
"devDependencies": {
"@cantoo/pdf-lib": "^2.7.1",
"@cantoo/pdf-lib": "^2.9.1",
"@google-cloud/kms": "^5.5.1",
"@google-cloud/secret-manager": "^6.1.3",
"@types/bun": "^1.3.14",
Expand Down
5 changes: 4 additions & 1 deletion scripts/bench-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import { readFileSync } from "node:fs";

import { getLibraryVersions } from "./bench-versions";

interface Bench {
name: string;
mean: number;
Expand Down Expand Up @@ -116,7 +118,8 @@ const runner = process.env.BENCH_RUNNER ?? "local";
lines.push(
`<details><summary>Environment</summary>\n\n` +
`- Runner: \`${runner}\`\n` +
`- Runtime: Bun ${process.versions.bun}\n\n` +
`- Runtime: Bun ${process.versions.bun}\n` +
`- Libraries: ${getLibraryVersions()}\n\n` +
`*Results are machine-dependent.*\n` +
`</details>`,
);
Expand Down
4 changes: 4 additions & 0 deletions scripts/bench-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { execSync } from "node:child_process";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { cpus, platform, totalmem } from "node:os";

import { getLibraryVersions } from "./bench-versions";

// ─────────────────────────────────────────────────────────────────────────────
// Types for vitest bench JSON output
// ─────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -122,6 +124,8 @@ function generateMarkdown(data: BenchmarkOutput): string {
lines.push(`> Generated on ${dateStr} at ${timeStr} UTC`);
lines.push(`>`);
lines.push(`> System: ${getSystemInfo()}`);
lines.push(`>`);
lines.push(`> Libraries: ${getLibraryVersions()}`);
lines.push("");
lines.push("---");
lines.push("");
Expand Down
64 changes: 64 additions & 0 deletions scripts/bench-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Resolves installed versions of the libraries used in benchmark comparisons.
*
* Versions are read from node_modules at generation time, so reports always
* reflect the packages that actually ran, not the semver ranges in
* package.json.
*/

import { readFileSync } from "node:fs";
import { join } from "node:path";

/** Competitor libraries used in benchmarks/comparison.bench.ts. */
export const COMPARISON_LIBRARIES = ["pdf-lib", "@cantoo/pdf-lib"] as const;

function readPackageMetadata(path: string): { name?: string; version?: string } {
const value: unknown = JSON.parse(readFileSync(path, "utf-8"));

if (typeof value !== "object" || value === null) {
return {};
}

const name = "name" in value && typeof value.name === "string" ? value.name : undefined;
const version =
"version" in value && typeof value.version === "string" ? value.version : undefined;

return { name, version };
}

/**
* Read the installed version of a package from node_modules.
* Returns "unknown" if the package cannot be resolved.
*/
export function getInstalledVersion(name: string, root = process.cwd()): string {
try {
const pkgPath = join(root, "node_modules", name, "package.json");
const pkg = readPackageMetadata(pkgPath);

return pkg.version ?? "unknown";
} catch {
return "unknown";
}
}

/**
* Format a one-line summary of all benchmarked library versions,
* e.g. "@libpdf/core 0.1.0 (this repo), pdf-lib 1.17.1, @cantoo/pdf-lib 2.9.1".
*/
export function getLibraryVersions(root = process.cwd()): string {
let ownLabel = "@libpdf/core";

try {
const pkg = readPackageMetadata(join(root, "package.json"));

ownLabel = `${pkg.name ?? "@libpdf/core"} ${pkg.version ?? "unknown"} (this repo)`;
} catch {
ownLabel = "@libpdf/core unknown (this repo)";
}

const competitors = COMPARISON_LIBRARIES.map(
name => `${name} ${getInstalledVersion(name, root)}`,
);

return [ownLabel, ...competitors].join(", ");
}
Loading