Skip to content

add cal.com.tsx #4

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
15 changes: 8 additions & 7 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ 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
runs-on: ubuntu-latest
steps:
- name: Checkout Branch
uses: actions/checkout@v4
- uses: taiki-e/checkout-action@v1

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

- name: Build Benchmark
run: cargo codspeed build --features codspeed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ oxc = { version = "0.13.5", features = ["transformer", "codegen"] }
swc = "0.276.0"
swc_common = "0.33.26"
swc_ecma_ast = "0.113.7"
swc_ecma_parser = "0.144.2"
swc_ecma_parser = { version = "0.144.2", features = ["typescript"] }
swc_ecma_transforms_react = "0.184.1"
swc_ecma_transforms_typescript = "0.189.1"
swc_ecma_visit = "0.99.1"

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"]
44 changes: 27 additions & 17 deletions benches/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ trait TheBencher {

const ID: &'static str;

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

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::run(source)));
g.bench_with_input(id, &source, |b, source| b.iter(|| Self::run(path, source)));

let id = BenchmarkId::new(Self::ID, "no-drop");
g.bench_with_input(id, &source, |b, source| {
b.iter_with_large_drop(|| Self::run(source))
b.iter_with_large_drop(|| Self::run(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::run(source);
Self::run(path, source);
});
})
});
Expand All @@ -41,7 +41,7 @@ impl TheBencher for OxcBencher {

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

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

let allocator = Allocator::default();
let source_type = SourceType::default();
let source_type = SourceType::from_path(path).unwrap();
{
let ret = Parser::new(&allocator, source_text, source_type).parse();
let trivias = ret.trivias;
Expand Down Expand Up @@ -86,22 +86,30 @@ impl TheBencher for SwcBencher {

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

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

let cm = Lrc::new(SourceMap::new(swc_common::FilePathMapping::empty()));
let compiler = Compiler::new(Arc::clone(&cm));
let comments = SwcComments::default();
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"),
};

GLOBALS.set(&Default::default(), || {
let program = Parser::new(
Syntax::Es(Default::default()),
syntax,
StringInput::new(source, Default::default(), Default::default()),
Some(&comments),
)
Expand Down Expand Up @@ -132,13 +140,15 @@ impl TheBencher for SwcBencher {
}

fn transformer_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);
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);
g.finish();
}
}

criterion_group!(transformer, transformer_benchmark);
Expand Down
Loading