mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 00:32:15 +03:00
perf(es/typescript): Add a benchmark for fast TS strip (#9205)
This commit is contained in:
parent
b0a3987cf5
commit
7d9364cad3
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4952,6 +4952,8 @@ name = "swc_fast_ts_strip"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"codspeed-criterion-compat",
|
||||
"criterion",
|
||||
"serde",
|
||||
"swc_common",
|
||||
"swc_ecma_ast",
|
||||
|
@ -20,4 +20,10 @@ swc_ecma_parser = { version = "0.146.9", path = "../swc_ecma_parser" }
|
||||
swc_ecma_visit = { version = "0.101.0", path = "../swc_ecma_visit" }
|
||||
|
||||
[dev-dependencies]
|
||||
testing = { version = "0.36.0", path = "../testing" }
|
||||
codspeed-criterion-compat = { workspace = true }
|
||||
criterion = { workspace = true }
|
||||
testing = { version = "0.36.0", path = "../testing" }
|
||||
|
||||
[[bench]]
|
||||
harness = false
|
||||
name = "assets"
|
||||
|
31
crates/swc_fast_ts_strip/benches/assets.rs
Normal file
31
crates/swc_fast_ts_strip/benches/assets.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};
|
||||
use swc_fast_ts_strip::{operate, Options};
|
||||
|
||||
static SOURCE: &str = include_str!("assets/test.ts");
|
||||
|
||||
fn fast_ts(c: &mut Criterion) {
|
||||
c.bench_function("typescript/fast-strip", fast_typescript);
|
||||
}
|
||||
fn fast_typescript(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
::testing::run_test(false, |cm, handler| {
|
||||
black_box(operate(
|
||||
&cm,
|
||||
handler,
|
||||
black_box(SOURCE.to_string()),
|
||||
Options {
|
||||
module: None,
|
||||
filename: None,
|
||||
parser: Default::default(),
|
||||
},
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, fast_ts);
|
||||
criterion_main!(benches);
|
198
crates/swc_fast_ts_strip/benches/assets/test.ts
Normal file
198
crates/swc_fast_ts_strip/benches/assets/test.ts
Normal file
@ -0,0 +1,198 @@
|
||||
let x /**/: number/**/ = 1!;
|
||||
// ^^^^^^^^ ^
|
||||
|
||||
[] as [] satisfies [];
|
||||
// ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
(<string>"test");
|
||||
//^^^^^^^^
|
||||
|
||||
class C /**/<T>/*︎*/ extends Array/**/<T> /*︎*/ implements I, J/*︎*/ {
|
||||
// ^^^^^ ^^^ ^^^^^^^^^^^^^^
|
||||
readonly field/**/: string/**/ = "";
|
||||
// ^^^^^^^^ ^^^^^^^^
|
||||
static accessor f1;
|
||||
private f2/**/!/**/: string/*︎*/;
|
||||
// ^^^^^^^ ^ ^^^^^^^^
|
||||
declare f3: any;
|
||||
// ^^^^^^^^^^^^^^^^ declared property
|
||||
|
||||
public method/**/<T>/*︎*/(/*︎*/this: T,/**/ a? /*︎*/: string/**/)/*︎*/: void/*︎*/ {
|
||||
// ^^^^^^ ^^^ ^^^^^^^^ ^ ^^^^^^^^ ^^^^^^
|
||||
}
|
||||
|
||||
[key: string]: any;
|
||||
// ^^^^^^^^^^^^^^^^^^^ index signature
|
||||
|
||||
get g(): any { return 1 };
|
||||
// ^^^^^
|
||||
set g(v: any) { };
|
||||
// ^^^^^
|
||||
}
|
||||
|
||||
class D extends C<any> {
|
||||
// ^^^^^
|
||||
override method(...args): any { }
|
||||
// ^^^^^^^^ ^^^^^
|
||||
}
|
||||
|
||||
abstract class A {
|
||||
// ^^^^^^^^
|
||||
abstract a;
|
||||
// ^^^^^^^^^^^ abstract property
|
||||
b;
|
||||
abstract method();
|
||||
// ^^^^^^^^^^^^^^^^^^ abstract method
|
||||
}
|
||||
|
||||
{
|
||||
let m = new (Map!)<string, number>([]!);
|
||||
// ^ ^^^^^^^^^^^^^^^^ ^
|
||||
}
|
||||
|
||||
{
|
||||
let a = (foo!)<any>;
|
||||
// ^ ^^^^^
|
||||
}
|
||||
|
||||
{
|
||||
let a = (foo!)<any>([]!);
|
||||
// ^ ^^^^^ ^
|
||||
}
|
||||
|
||||
{
|
||||
let f = function (p: any) { }
|
||||
// ^^^^^
|
||||
}
|
||||
|
||||
{
|
||||
function overload(): number;
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overload
|
||||
function overload(): any { }
|
||||
// ^^^^^
|
||||
}
|
||||
|
||||
/** @doc */
|
||||
interface I { }
|
||||
// ^^^^^^^^^^^ interface
|
||||
|
||||
void 0;
|
||||
|
||||
/** @doc */
|
||||
type J = I;
|
||||
// ^^^^^^^^ type alias
|
||||
|
||||
/**/import type T from "node:assert";
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `import type`
|
||||
|
||||
/**/export type { I };
|
||||
// ^^^^^^^^^^^^^^^^^^ `export type`
|
||||
|
||||
/**/export type * from "node:buffer";
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `export type *`
|
||||
|
||||
import { type AssertPredicate/**/, deepEqual } from "node:assert";
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
export {
|
||||
C,
|
||||
type T,
|
||||
// ^^^^^^
|
||||
}
|
||||
|
||||
/**/export type T2 = 1;
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
function foo<T>(p: any = (): any => 1): any {
|
||||
// ^^^ ^^^^^ ^^^^^ ^^^^^
|
||||
return p as any;
|
||||
// ^^^^^^
|
||||
}
|
||||
|
||||
/**/declare enum E1 { }
|
||||
// ^^^^^^^^^^^^^^^^^^ `declare enum`
|
||||
|
||||
void 0;
|
||||
|
||||
/**/declare namespace N { }
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^ `declare namespace`
|
||||
|
||||
void 0;
|
||||
|
||||
/**/declare module M { }
|
||||
// ^^^^^^^^^^^^^^^^^^^ `declare module`
|
||||
|
||||
void 0;
|
||||
|
||||
/**/declare let a;
|
||||
// ^^^^^^^^^^^^^^ `declare let`
|
||||
|
||||
void 0;
|
||||
|
||||
/**/declare class DeclaredClass { }
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `declare class`
|
||||
|
||||
void 0;
|
||||
|
||||
/**/declare function DeclaredFunction(): void;
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `declare function`
|
||||
|
||||
void 0;
|
||||
|
||||
// `=>` spanning line cases:
|
||||
{
|
||||
()
|
||||
: any =>
|
||||
1
|
||||
};
|
||||
{
|
||||
():
|
||||
any =>
|
||||
1
|
||||
};
|
||||
{
|
||||
(
|
||||
)
|
||||
: any =>
|
||||
1
|
||||
};
|
||||
{
|
||||
(
|
||||
): (
|
||||
| any
|
||||
) =>
|
||||
1
|
||||
};
|
||||
{
|
||||
(
|
||||
):
|
||||
NonNullable<any
|
||||
> =>
|
||||
1
|
||||
};
|
||||
{
|
||||
(a, b, c: D = [] as any/*comment-1*/)/*comment-2*/:
|
||||
any =>
|
||||
1
|
||||
};
|
||||
|
||||
|
||||
():
|
||||
any =>
|
||||
1;
|
||||
|
||||
{
|
||||
(a, b, c: D = [] as any/*comment-1*/)/*comment-2*/:
|
||||
/*comment-3*/any/*comment-4*/ =>
|
||||
1
|
||||
};
|
||||
|
||||
type 任意の型 = any;
|
||||
|
||||
():
|
||||
任意の型 =>
|
||||
1;
|
||||
|
||||
()/*comment-1*/:/*comment-2*/
|
||||
/*comment-3*/任意の型/*comment-4*/ =>
|
||||
1;
|
Loading…
Reference in New Issue
Block a user