Skip to content

Commit

Permalink
bench: add TypeScript (#9)
Browse files Browse the repository at this point in the history
```

❯ pnpm bench

> [email protected] bench /Users/brooklyn/workspace/github/oxc-node
> pnpm --filter=bench bench


> [email protected] 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     │
└─────────┴──────────────┴─────────┴────────────────────┴──────────┴─────────┘

```
  • Loading branch information
Brooooooklyn authored Jul 14, 2024
1 parent 63c72d6 commit 347f8be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion packages/bench/index.ts
Original file line number Diff line number Diff line change
@@ -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 })

Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion packages/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 347f8be

Please sign in to comment.