Skip to content

Commit e54ed90

Browse files
benchmark: add Windows compatibility (#3628)
1. use local git clone instead of git archive | tar 2. normalize module path within sampleCode Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
1 parent b91f51b commit e54ed90

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

resources/benchmark.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as cp from 'node:child_process';
33
import * as fs from 'node:fs';
44
import * as os from 'node:os';
55
import * as path from 'node:path';
6+
import * as url from 'node:url';
67

78
import { localRepoPath } from './utils';
89

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

376378
function sampleModule(modulePath: string): BenchmarkSample {
379+
// To support Windows we need to use URL instead of path
380+
const moduleURL = url.pathToFileURL(modulePath);
381+
377382
const sampleCode = `
378383
import fs from 'node:fs';
379384
380-
import { benchmark } from '${modulePath}';
385+
import { benchmark } from '${moduleURL}';
381386
382387
// warm up, it looks like 7 is a magic number to reliably trigger JIT
383388
benchmark.measure();

0 commit comments

Comments
 (0)