Skip to content

add cal.com.tsx #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
- 'Cargo.lock'
- 'rust-toolchain.toml'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

jobs:
benchmark:
name: Benchmark
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ panic = "abort"

[dependencies]
oxc = "0.13.5"
swc_ecma_parser = "0.144.2"

swc_ecma_parser = { version = "0.144.2", features = ["typescript"] }
swc_ecma_ast = "0.113.7"

biome_js_parser = "0.5.7"
biome_js_syntax = "0.5.7"

num_cpus = "1.16.0"
criterion2 = { version = "0.10.0", default-features = false }
rayon = "1.10.0"
mimalloc = "0.1.41"
mimalloc = "0.1.42"

[features]
codspeed = ["criterion2/codspeed"]
58 changes: 37 additions & 21 deletions benches/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::Path;

use criterion::{measurement::WallTime, *};
use rayon::prelude::*;

Expand All @@ -9,23 +11,25 @@ trait TheBencher {

const ID: &'static str;

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

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

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

let id = BenchmarkId::new(Self::ID, "parallel");
g.bench_with_input(id, &source, |b, source| {
b.iter(|| {
(0..cpus).into_par_iter().for_each(|_| {
Self::parse(source);
Self::parse(path, source);
});
})
});
Expand All @@ -39,9 +43,9 @@ impl TheBencher for OxcBencher {

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

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

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

fn parse(source: &str) -> Self::ParseOutput {
use swc_ecma_parser::{Parser, StringInput, Syntax};
fn parse(path: &Path, source: &str) -> Self::ParseOutput {
use swc_ecma_parser::{EsConfig, Parser, StringInput, Syntax, TsConfig};
let syntax = match path.extension().unwrap().to_str().unwrap() {
"js" => Syntax::Es(EsConfig::default()),
"tsx" => Syntax::Typescript(TsConfig {
tsx: true,
..TsConfig::default()
}),
_ => panic!("need to define syntax for swc"),
};
Parser::new(
Syntax::Es(Default::default()),
syntax,
StringInput::new(source, Default::default(), Default::default()),
None,
)
Expand All @@ -68,24 +80,28 @@ impl TheBencher for SwcBencher {
struct BiomeBencher;

impl TheBencher for BiomeBencher {
type ParseOutput = biome_js_parser::Parse<biome_js_syntax::JsModule>;
type ParseOutput = biome_js_parser::Parse<biome_js_syntax::AnyJsRoot>;

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

fn parse(source: &str) -> Self::ParseOutput {
biome_js_parser::parse_module(source, biome_js_parser::JsParserOptions::default())
fn parse(path: &Path, source: &str) -> Self::ParseOutput {
let options = biome_js_parser::JsParserOptions::default();
let source_type = biome_js_syntax::JsFileSource::try_from(path).unwrap();
biome_js_parser::parse(source, source_type, options)
}
}

fn parser_benchmark(c: &mut Criterion) {
let filename = "typescript.js";
let source = std::fs::read_to_string(filename).unwrap();

let mut g = c.benchmark_group(filename);
OxcBencher::bench(&mut g, &source);
SwcBencher::bench(&mut g, &source);
BiomeBencher::bench(&mut g, &source);
g.finish();
let filenames = ["typescript.js", "cal.com.tsx"];
for filename in filenames {
let path = Path::new("files").join(filename);
let source = std::fs::read_to_string(&path).unwrap();
let mut g = c.benchmark_group(filename);
OxcBencher::bench(&mut g, &path, &source);
SwcBencher::bench(&mut g, &path, &source);
BiomeBencher::bench(&mut g, &path, &source);
g.finish();
}
}

criterion_group!(parser, parser_benchmark);
Expand Down
Loading