From 347f8beea8726b4700bdb7cfdee9df35cddbc250 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Sun, 14 Jul 2024 19:57:59 +0800 Subject: [PATCH] bench: add TypeScript (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` ❯ pnpm bench > oxc-node@0.0.0 bench /Users/brooklyn/workspace/github/oxc-node > pnpm --filter=bench bench > bench@0.0.0 bench /Users/brooklyn/workspace/github/oxc-node/packages/bench > node --import @oxc-node/core/register index.ts ┌─────────┬──────────────┬─────────┬────────────────────┬──────────┬─────────┐ │ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │ ├─────────┼──────────────┼─────────┼────────────────────┼──────────┼─────────┤ │ 0 │ '@swc/core' │ '1,539' │ 649450.8402597416 │ '±0.44%' │ 1540 │ │ 1 │ 'oxc' │ '7,004' │ 142768.56045681832 │ '±0.07%' │ 7005 │ │ 2 │ 'typescript' │ '304' │ 3284196.5836065547 │ '±2.80%' │ 305 │ └─────────┴──────────────┴─────────┴────────────────────┴──────────┴─────────┘ ``` --- packages/bench/index.ts | 14 +++++++++++++- packages/bench/package.json | 3 ++- pnpm-lock.yaml | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/bench/index.ts b/packages/bench/index.ts index 596f4e9..ef8b7e8 100644 --- a/packages/bench/index.ts +++ b/packages/bench/index.ts @@ -1,10 +1,11 @@ import { readFile } from 'node:fs/promises' import { join } from 'node:path' +import { fileURLToPath } from 'node:url' import { transformSync } from '@swc/core' import { transform as oxc } from '@oxc-node/core' import { Bench } from 'tinybench' -import { fileURLToPath } from 'node:url' +import ts from 'typescript' const bench = new Bench({ time: 1000 }) @@ -30,6 +31,17 @@ bench .add('oxc', () => { oxc('ajax.ts', fixture) }) + .add('typescript', () => { + ts.transpileModule(fixture, { + fileName: 'ajax.ts', + compilerOptions: { + target: ts.ScriptTarget.ESNext, + module: ts.ModuleKind.ESNext, + isolatedModules: true, + sourceMap: true, + }, + }) + }) await bench.warmup() // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50 await bench.run() diff --git a/packages/bench/package.json b/packages/bench/package.json index 08d71cb..b0859e7 100644 --- a/packages/bench/package.json +++ b/packages/bench/package.json @@ -10,6 +10,7 @@ "@oxc-node/core": "workspace:*", "@swc/core": "=1.6.7", "tinybench": "^2.8.0", - "rxjs": "^7.8.1" + "rxjs": "^7.8.1", + "typescript": "^5.5.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da839ca..1a71531 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,6 +68,9 @@ importers: tinybench: specifier: ^2.8.0 version: 2.8.0 + typescript: + specifier: ^5.5.3 + version: 5.5.3 packages/core: {}