@@ -12,6 +12,9 @@ const abortButton = document.getElementById("abort");
1212const startButton = document . getElementById ( "start" ) ;
1313const results = document . getElementById ( "results" ) ;
1414
15+ const standaloneInput = document . getElementById ( "standalone" ) ;
16+ const iterationsInput = document . getElementById ( "iterations" ) ;
17+
1518// This allows aborting and outputting while tests are being run.
1619Benchmark . options . async = true ;
1720
@@ -38,17 +41,22 @@ function addResult(name, result, fn) {
3841// @see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
3942const semverRegex = / ^ ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) (?: - ( (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) (?: \. (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) ) * ) ) ? (?: \+ ( [ 0 - 9 a - z A - Z - ] + (?: \. [ 0 - 9 a - z A - Z - ] + ) * ) ) ? $ / ;
4043
41- window . start = function ( ) {
42- const benchmarks = benchmarksInput . value . trim ( ) !== "" ? benchmarksInput . value . split ( "," ) : available ;
43-
44- document . getElementById ( "started" ) . style . display = "block" ;
45-
44+ function getUrl ( ) {
4645 let url = urlInput . value ;
4746 if ( url . trim ( ) === "" ) {
4847 url = "vue.global.js" ;
4948 } else if ( semverRegex . test ( url ) ) {
5049 url = `https://cdnjs.cloudflare.com/ajax/libs/vue/${ url } /vue.global.js` ;
5150 }
51+ return url ;
52+ }
53+
54+ window . start = function ( ) {
55+ const benchmarks = benchmarksInput . value . trim ( ) !== "" ? benchmarksInput . value . split ( "," ) : available ;
56+
57+ document . getElementById ( "started" ) . style . display = "block" ;
58+
59+ let url = getUrl ( ) ;
5260
5361 log ( "Use Vue3: " + url ) ;
5462 log ( "Benchmarks: " + benchmarks . join ( "," ) ) ;
@@ -112,6 +120,57 @@ async function runTests(benchmarks) {
112120 }
113121}
114122
123+ window . standalone = function ( ) {
124+ const v = standaloneInput . value ;
125+ const index = v . indexOf ( ":" ) ;
126+ if ( index === - 1 ) {
127+ alert ( "Format: {name}:{benchmark}" ) ;
128+ } else {
129+ const name = v . substr ( 0 , index ) . trim ( ) ;
130+ const bench = v . substr ( index + 1 ) . trim ( ) ;
131+ startStandalone ( name , bench ) ;
132+ }
133+ }
134+
135+ async function startStandalone ( name , benchmarkName ) {
136+ let url = getUrl ( ) ;
137+
138+ log ( "Use Vue3: " + url ) ;
139+ log ( "Benchmarks: " + name + ":" + benchmarkName ) ;
140+
141+ await injectScript ( url ) ;
142+
143+ window . go = undefined ;
144+ await injectScript ( `src/${ name } .js` ) ;
145+
146+ suite = go ( ) ;
147+
148+ let bench ;
149+ for ( const key in suite ) {
150+ if ( parseInt ( key ) >= 0 ) {
151+ const b = suite [ key ] ;
152+ if ( b . name === benchmarkName ) {
153+ bench = b ;
154+ }
155+ }
156+ }
157+
158+ if ( ! bench ) {
159+ alert ( "Benchmark not found." ) ;
160+ return ;
161+ }
162+
163+ const iterations = parseInt ( iterationsInput . value . replace ( / _ / g, "" ) ) || 1e4 ;
164+ log ( "Iterations: " + iterations ) ;
165+
166+ const f = bench . fn ;
167+ console . profile ( benchmarkName ) ;
168+ for ( let i = 0 ; i < iterations ; i ++ ) {
169+ f ( ) ;
170+ }
171+ console . profileEnd ( benchmarkName ) ;
172+ }
173+
115174function injectScript ( src ) {
116175 return new Promise ( ( resolve , reject ) => {
117176 const script = document . createElement ( 'script' ) ;
@@ -121,3 +180,5 @@ function injectScript(src) {
121180 document . head . appendChild ( script ) ;
122181 } ) ;
123182}
183+
184+
0 commit comments