File tree Expand file tree Collapse file tree
packages/babel-parser/benchmark/many-let-declarations Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Benchmark from "benchmark" ;
2+ import baseline from "@babel-baseline/parser" ;
3+ import current from "../../lib/index.js" ;
4+ import { report } from "../util.mjs" ;
5+
6+ const suite = new Benchmark . Suite ( ) ;
7+ // All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13
8+ function createInput ( length ) {
9+ if ( length > 0x9ffc - 0x4e00 ) {
10+ throw new Error (
11+ `Length greater than ${
12+ 0x9ffc - 0x4e00
13+ } is not supported! Consider modify the \`createInput\`.`
14+ ) ;
15+ }
16+ let source = "" ;
17+ for ( let i = 0 ; i < length ; i ++ ) {
18+ source += "let " + String . fromCharCode ( 0x4e00 + i ) + ";" ;
19+ }
20+ return source ;
21+ }
22+ function benchCases ( name , implementation , options ) {
23+ for ( const length of [ 256 , 512 , 1024 , 2048 ] ) {
24+ const input = createInput ( length ) ;
25+ suite . add ( `${ name } ${ length } length-1 let bindings` , ( ) => {
26+ implementation . parse ( input , options ) ;
27+ } ) ;
28+ }
29+ }
30+
31+ benchCases ( "baseline" , baseline ) ;
32+ benchCases ( "current" , current ) ;
33+
34+ suite . on ( "cycle" , report ) . run ( ) ;
You can’t perform that action at this time.
0 commit comments