Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jun 13, 2024
1 parent e3dd9ec commit 32c9e30
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 16 additions & 1 deletion crates/swc_ecma_parser/benches/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate swc_malloc;

use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use swc_common::FileName;
use swc_ecma_parser::{lexer::Lexer, StringInput, Syntax};
use swc_ecma_parser::{lexer::Lexer, StringInput, Syntax, TsConfig};

fn bench_module(b: &mut Bencher, syntax: Syntax, src: &'static str) {
let _ = ::testing::run_test(false, |cm, _| {
Expand Down Expand Up @@ -82,6 +82,21 @@ fn bench_files(c: &mut Criterion) {
c.bench_function("es/lexer/yui", |b| {
bench_module(b, Default::default(), include_str!("./files/yui-3.12.0.js"))
});

c.bench_function("es/lexer/cal-com", |b| {
bench_module(
b,
Syntax::Typescript(TsConfig {
tsx: true,
..Default::default()
}),
include_str!("./files/cal.com.tsx"),
)
});

c.bench_function("es/lexer/typescript", |b| {
bench_module(b, Default::default(), include_str!("./files/typescript.js"))
});
}

criterion_group!(benches, bench_files);
Expand Down
17 changes: 16 additions & 1 deletion crates/swc_ecma_parser/benches/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate swc_malloc;

use criterion::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use swc_common::{comments::SingleThreadedComments, FileName};
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax};
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsConfig};

fn bench_module(b: &mut Bencher, syntax: Syntax, src: &'static str) {
let _ = ::testing::run_test(false, |cm, _| {
Expand Down Expand Up @@ -89,6 +89,21 @@ fn bench_files(c: &mut Criterion) {
c.bench_function("es/parser/yui", |b| {
bench_module(b, Default::default(), include_str!("./files/yui-3.12.0.js"))
});

c.bench_function("es/parser/cal-com", |b| {
bench_module(
b,
Syntax::Typescript(TsConfig {
tsx: true,
..Default::default()
}),
include_str!("./files/cal.com.tsx"),
)
});

c.bench_function("es/parser/typescript", |b| {
bench_module(b, Default::default(), include_str!("./files/typescript.js"))
});
}

criterion_group!(benches, bench_files);
Expand Down

0 comments on commit 32c9e30

Please sign in to comment.