Skip to content

Commit

Permalink
chore(napi): add oxc-parser to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Mar 15, 2024
1 parent 53a8e7f commit 549ec9a
Show file tree
Hide file tree
Showing 5 changed files with 1,090 additions and 7 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -38,6 +38,12 @@ jobs:
shared-key: 'benchmark'
save-cache: ${{ github.ref_name == 'main' }}

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Install codspeed
uses: taiki-e/install-action@v2
with:
Expand All @@ -59,9 +65,19 @@ jobs:
mv target/release/deps/codegen_sourcemap-* target/codspeed/oxc_benchmark
rm -rf target/codspeed/oxc_benchmark/*.d
- name: Build NAPI benchmark
working-directory: ./napi/parser
run: |
corepack enable
pnpm install
pnpm run build
- name: Run benchmark
uses: CodSpeedHQ/action@v2
timeout-minutes: 30
with:
run: cargo codspeed run
run: |
cargo codspeed run
cd napi/parser
pnpm run bench
token: ${{ secrets.CODSPEED_TOKEN }}
9 changes: 6 additions & 3 deletions napi/parser/package.json
Expand Up @@ -3,17 +3,20 @@
"private": true,
"scripts": {
"build": "napi build --platform --release",
"test": "node test.mjs"
"test": "node test.mjs",
"bench": "vitest bench"
},
"devDependencies": {
"@codspeed/vitest-plugin": "^3.1.0",
"@napi-rs/cli": "^2.18.0",
"es-module-lexer": "^1.4.1",
"flatbuffers": "^23.5.26"
"flatbuffers": "^23.5.26",
"vitest": "^1.3.1"
},
"engines": {
"node": ">=14.*"
},
"packageManager": "pnpm@8.2.0",
"packageManager": "pnpm@8.15.4+sha256.cea6d0bdf2de3a0549582da3983c70c92ffc577ff4410cbf190817ddc35137c2",
"napi": {
"name": "parser",
"triples": {
Expand Down
45 changes: 45 additions & 0 deletions napi/parser/parse.bench.mjs
@@ -0,0 +1,45 @@
import {fileURLToPath} from 'url';
import {join as pathJoin} from 'path';
import {readFile, writeFile} from 'fs/promises';
import {bench} from 'vitest';
import {parseSync} from './index.js';

const urls = [
// TypeScript syntax (2.81MB)
'https://raw.githubusercontent.com/microsoft/TypeScript/v5.3.3/src/compiler/checker.ts',
// Real world app tsx (1.0M)
'https://raw.githubusercontent.com/oxc-project/benchmark-files/main/cal.com.tsx',
// Real world content-heavy app jsx (3K)
'https://raw.githubusercontent.com/oxc-project/benchmark-files/main/RadixUIAdoptionSection.jsx',
// Heavy with classes (554K)
'https://cdn.jsdelivr.net/npm/pdfjs-dist@4.0.269/build/pdf.mjs',
// ES5 (3.9M)
'https://cdn.jsdelivr.net/npm/antd@5.12.5/dist/antd.js',
];

// Same directory as Rust benchmarks use for downloaded files
const cacheDirPath = pathJoin(fileURLToPath(import.meta.url), '../../../target');

const files = await Promise.all(urls.map(async (url) => {
const filename = url.split('/').at(-1),
path = pathJoin(cacheDirPath, filename);

let code;
try {
code = await readFile(path, 'utf8');
console.log('Found cached file:', filename);
} catch {
console.log('Downloading:', filename);
const res = await fetch(url);
code = await res.text();
await writeFile(path, code);
}

return {filename, code};
}));

for (const {filename, code} of files) {
bench(`parser(napi)[${filename}]`, () => {
parseSync(code, {sourceFilename: filename});
});
}

0 comments on commit 549ec9a

Please sign in to comment.