Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 79a917a

Browse files
committedJun 8, 2024··
add cal.com.tsx
1 parent c70ae83 commit 79a917a

File tree

6 files changed

+30638
-25
lines changed

6 files changed

+30638
-25
lines changed
 

‎.github/workflows/benchmark.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ 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

‎Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ panic = "abort"
1818

1919
[dependencies]
2020
oxc = "0.13.5"
21-
swc_ecma_parser = "0.144.2"
21+
22+
swc_ecma_parser = { version = "0.144.2", features = ["typescript"] }
2223
swc_ecma_ast = "0.113.7"
24+
2325
biome_js_parser = "0.5.7"
2426
biome_js_syntax = "0.5.7"
2527

2628
num_cpus = "1.16.0"
2729
criterion2 = { version = "0.10.0", default-features = false }
2830
rayon = "1.10.0"
29-
mimalloc = "0.1.41"
31+
mimalloc = "0.1.42"
3032

3133
[features]
3234
codspeed = ["criterion2/codspeed"]

‎benches/parser.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::Path;
2+
13
use criterion::{measurement::WallTime, *};
24
use rayon::prelude::*;
35

@@ -9,23 +11,25 @@ trait TheBencher {
911

1012
const ID: &'static str;
1113

12-
fn parse(source: &str) -> Self::ParseOutput;
14+
fn parse(filename: &Path, source: &str) -> Self::ParseOutput;
1315

14-
fn bench(g: &mut BenchmarkGroup<'_, WallTime>, source: &str) {
16+
fn bench(g: &mut BenchmarkGroup<'_, WallTime>, path: &Path, source: &str) {
1517
let cpus = num_cpus::get_physical();
1618
let id = BenchmarkId::new(Self::ID, "single-thread");
17-
g.bench_with_input(id, &source, |b, source| b.iter(|| Self::parse(source)));
19+
g.bench_with_input(id, &source, |b, source| {
20+
b.iter(|| Self::parse(path, source))
21+
});
1822

1923
let id = BenchmarkId::new(Self::ID, "no-drop");
2024
g.bench_with_input(id, &source, |b, source| {
21-
b.iter_with_large_drop(|| Self::parse(source))
25+
b.iter_with_large_drop(|| Self::parse(path, source))
2226
});
2327

2428
let id = BenchmarkId::new(Self::ID, "parallel");
2529
g.bench_with_input(id, &source, |b, source| {
2630
b.iter(|| {
2731
(0..cpus).into_par_iter().for_each(|_| {
28-
Self::parse(source);
32+
Self::parse(path, source);
2933
});
3034
})
3135
});
@@ -39,9 +43,9 @@ impl TheBencher for OxcBencher {
3943

4044
const ID: &'static str = "oxc";
4145

42-
fn parse(source: &str) -> Self::ParseOutput {
46+
fn parse(path: &Path, source: &str) -> Self::ParseOutput {
4347
let allocator = oxc::allocator::Allocator::default();
44-
let source_type = oxc::span::SourceType::default();
48+
let source_type = oxc::span::SourceType::from_path(path).unwrap();
4549
_ = oxc::parser::Parser::new(&allocator, source, source_type).parse();
4650
allocator
4751
}
@@ -54,10 +58,18 @@ impl TheBencher for SwcBencher {
5458

5559
const ID: &'static str = "swc";
5660

57-
fn parse(source: &str) -> Self::ParseOutput {
58-
use swc_ecma_parser::{Parser, StringInput, Syntax};
61+
fn parse(path: &Path, source: &str) -> Self::ParseOutput {
62+
use swc_ecma_parser::{EsConfig, Parser, StringInput, Syntax, TsConfig};
63+
let syntax = match path.extension().unwrap().to_str().unwrap() {
64+
"js" => Syntax::Es(EsConfig::default()),
65+
"tsx" => Syntax::Typescript(TsConfig {
66+
tsx: true,
67+
..TsConfig::default()
68+
}),
69+
_ => panic!("need to define syntax for swc"),
70+
};
5971
Parser::new(
60-
Syntax::Es(Default::default()),
72+
syntax,
6173
StringInput::new(source, Default::default(), Default::default()),
6274
None,
6375
)
@@ -68,24 +80,28 @@ impl TheBencher for SwcBencher {
6880
struct BiomeBencher;
6981

7082
impl TheBencher for BiomeBencher {
71-
type ParseOutput = biome_js_parser::Parse<biome_js_syntax::JsModule>;
83+
type ParseOutput = biome_js_parser::Parse<biome_js_syntax::AnyJsRoot>;
7284

7385
const ID: &'static str = "biome";
7486

75-
fn parse(source: &str) -> Self::ParseOutput {
76-
biome_js_parser::parse_module(source, biome_js_parser::JsParserOptions::default())
87+
fn parse(path: &Path, source: &str) -> Self::ParseOutput {
88+
let options = biome_js_parser::JsParserOptions::default();
89+
let source_type = biome_js_syntax::JsFileSource::try_from(path).unwrap();
90+
biome_js_parser::parse(source, source_type, options)
7791
}
7892
}
7993

8094
fn parser_benchmark(c: &mut Criterion) {
81-
let filename = "typescript.js";
82-
let source = std::fs::read_to_string(filename).unwrap();
83-
84-
let mut g = c.benchmark_group(filename);
85-
OxcBencher::bench(&mut g, &source);
86-
SwcBencher::bench(&mut g, &source);
87-
BiomeBencher::bench(&mut g, &source);
88-
g.finish();
95+
let filenames = ["typescript.js", "cal.com.tsx"];
96+
for filename in filenames {
97+
let path = Path::new("files").join(filename);
98+
let source = std::fs::read_to_string(&path).unwrap();
99+
let mut g = c.benchmark_group(filename);
100+
OxcBencher::bench(&mut g, &path, &source);
101+
SwcBencher::bench(&mut g, &path, &source);
102+
BiomeBencher::bench(&mut g, &path, &source);
103+
g.finish();
104+
}
89105
}
90106

91107
criterion_group!(parser, parser_benchmark);

‎files/cal.com.tsx

Lines changed: 30591 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.