-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(es/typescript): Add a benchmark for fast TS strip (#9205)
- Loading branch information
Showing
4 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |