Skip to content

benchmark: add Windows compatibility #3628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2022
Merged
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
9 changes: 7 additions & 2 deletions resources/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as cp from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import * as url from 'node:url';

import { localRepoPath } from './utils';

Expand Down Expand Up @@ -95,7 +96,8 @@ function prepareBenchmarkProjects(
const repoDir = path.join(tmpDir, hash);
fs.rmSync(repoDir, { recursive: true, force: true });
fs.mkdirSync(repoDir);
exec(`git archive "${hash}" | tar -xC "${repoDir}"`);
exec(`git clone --quiet "${localRepoPath()}" "${repoDir}"`);
exec(`git checkout --quiet --detach "${hash}"`, { cwd: repoDir });
exec('npm --quiet ci --ignore-scripts', { cwd: repoDir });
fs.renameSync(buildNPMArchive(repoDir), archivePath);
fs.rmSync(repoDir, { recursive: true });
Expand Down Expand Up @@ -374,10 +376,13 @@ interface BenchmarkSample {
}

function sampleModule(modulePath: string): BenchmarkSample {
// To support Windows we need to use URL instead of path
const moduleURL = url.pathToFileURL(modulePath);

const sampleCode = `
import fs from 'node:fs';

import { benchmark } from '${modulePath}';
import { benchmark } from '${moduleURL}';

// warm up, it looks like 7 is a magic number to reliably trigger JIT
benchmark.measure();
Expand Down