Skip to content

Commit 2b53239

Browse files
authored
add cal.com.tsx (#4)
1 parent d04a95f commit 2b53239

File tree

5 files changed

+30628
-26
lines changed

5 files changed

+30628
-26
lines changed

.github/workflows/benchmark.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ on:
1616
- 'Cargo.lock'
1717
- 'rust-toolchain.toml'
1818

19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
21+
cancel-in-progress: ${{ github.ref_name != 'main' }}
22+
1923
jobs:
2024
benchmark:
2125
name: Benchmark
2226
runs-on: ubuntu-latest
2327
steps:
24-
- name: Checkout Branch
25-
uses: actions/checkout@v4
28+
- uses: taiki-e/checkout-action@v1
2629

27-
- name: Setup rust toolchain, cache and cargo-codspeed binary
28-
uses: moonrepo/setup-rust@v1
30+
- uses: Boshen/setup-rust@main
2931
with:
30-
channel: stable
31-
cache-target: release
32-
bins: cargo-codspeed
32+
save-cache: ${{ github.ref_name == 'main' }}
33+
tools: cargo-codspeed
3334

3435
- name: Build Benchmark
3536
run: cargo codspeed build --features codspeed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ oxc = { version = "0.13.5", features = ["transformer", "codegen"] }
2222
swc = "0.276.0"
2323
swc_common = "0.33.26"
2424
swc_ecma_ast = "0.113.7"
25-
swc_ecma_parser = "0.144.2"
25+
swc_ecma_parser = { version = "0.144.2", features = ["typescript"] }
2626
swc_ecma_transforms_react = "0.184.1"
2727
swc_ecma_transforms_typescript = "0.189.1"
2828
swc_ecma_visit = "0.99.1"
2929

3030
num_cpus = "1.16.0"
3131
criterion2 = { version = "0.10.0", default-features = false }
3232
rayon = "1.10.0"
33-
mimalloc = "0.1.41"
33+
mimalloc = "0.1.42"
3434

3535
[features]
3636
codspeed = ["criterion2/codspeed"]

benches/transformer.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ trait TheBencher {
1111

1212
const ID: &'static str;
1313

14-
fn run(source: &str) -> Self::RunOutput;
14+
fn run(path: &Path, source: &str) -> Self::RunOutput;
1515

16-
fn bench(g: &mut BenchmarkGroup<'_, WallTime>, source: &str) {
16+
fn bench(g: &mut BenchmarkGroup<'_, WallTime>, path: &Path, source: &str) {
1717
let cpus = num_cpus::get_physical();
1818
let id = BenchmarkId::new(Self::ID, "single-thread");
19-
g.bench_with_input(id, &source, |b, source| b.iter(|| Self::run(source)));
19+
g.bench_with_input(id, &source, |b, source| b.iter(|| Self::run(path, source)));
2020

2121
let id = BenchmarkId::new(Self::ID, "no-drop");
2222
g.bench_with_input(id, &source, |b, source| {
23-
b.iter_with_large_drop(|| Self::run(source))
23+
b.iter_with_large_drop(|| Self::run(path, source))
2424
});
2525

2626
let id = BenchmarkId::new(Self::ID, "parallel");
2727
g.bench_with_input(id, &source, |b, source| {
2828
b.iter(|| {
2929
(0..cpus).into_par_iter().for_each(|_| {
30-
Self::run(source);
30+
Self::run(path, source);
3131
});
3232
})
3333
});
@@ -41,7 +41,7 @@ impl TheBencher for OxcBencher {
4141

4242
const ID: &'static str = "oxc";
4343

44-
fn run(source_text: &str) -> Self::RunOutput {
44+
fn run(path: &Path, source_text: &str) -> Self::RunOutput {
4545
use oxc::{
4646
allocator::Allocator,
4747
codegen::{Codegen, CodegenOptions},
@@ -51,7 +51,7 @@ impl TheBencher for OxcBencher {
5151
};
5252

5353
let allocator = Allocator::default();
54-
let source_type = SourceType::default();
54+
let source_type = SourceType::from_path(path).unwrap();
5555
{
5656
let ret = Parser::new(&allocator, source_text, source_type).parse();
5757
let trivias = ret.trivias;
@@ -86,22 +86,30 @@ impl TheBencher for SwcBencher {
8686

8787
const ID: &'static str = "swc";
8888

89-
fn run(source: &str) -> Self::RunOutput {
89+
fn run(path: &Path, source: &str) -> Self::RunOutput {
9090
use std::sync::Arc;
9191
use swc::{Compiler, PrintArgs, SwcComments};
9292
use swc_common::{chain, source_map::SourceMap, sync::Lrc, Mark, GLOBALS};
93-
use swc_ecma_parser::{Parser, StringInput, Syntax};
93+
use swc_ecma_parser::{EsConfig, Parser, StringInput, Syntax, TsConfig};
9494
use swc_ecma_transforms_react::{react, Options};
9595
use swc_ecma_transforms_typescript::strip;
9696
use swc_ecma_visit::FoldWith;
9797

9898
let cm = Lrc::new(SourceMap::new(swc_common::FilePathMapping::empty()));
9999
let compiler = Compiler::new(Arc::clone(&cm));
100100
let comments = SwcComments::default();
101+
let syntax = match path.extension().unwrap().to_str().unwrap() {
102+
"js" => Syntax::Es(EsConfig::default()),
103+
"tsx" => Syntax::Typescript(TsConfig {
104+
tsx: true,
105+
..TsConfig::default()
106+
}),
107+
_ => panic!("need to define syntax for swc"),
108+
};
101109

102110
GLOBALS.set(&Default::default(), || {
103111
let program = Parser::new(
104-
Syntax::Es(Default::default()),
112+
syntax,
105113
StringInput::new(source, Default::default(), Default::default()),
106114
Some(&comments),
107115
)
@@ -132,13 +140,15 @@ impl TheBencher for SwcBencher {
132140
}
133141

134142
fn transformer_benchmark(c: &mut Criterion) {
135-
let filename = "typescript.js";
136-
let source = std::fs::read_to_string(filename).unwrap();
137-
138-
let mut g = c.benchmark_group(filename);
139-
OxcBencher::bench(&mut g, &source);
140-
SwcBencher::bench(&mut g, &source);
141-
g.finish();
143+
let filenames = ["typescript.js", "cal.com.tsx"];
144+
for filename in filenames {
145+
let path = Path::new("files").join(filename);
146+
let source = std::fs::read_to_string(&path).unwrap();
147+
let mut g = c.benchmark_group(filename);
148+
OxcBencher::bench(&mut g, &path, &source);
149+
SwcBencher::bench(&mut g, &path, &source);
150+
g.finish();
151+
}
142152
}
143153

144154
criterion_group!(transformer, transformer_benchmark);

0 commit comments

Comments
 (0)