@@ -12,6 +12,9 @@ const abortButton = document.getElementById("abort");
12
12
const startButton = document . getElementById ( "start" ) ;
13
13
const results = document . getElementById ( "results" ) ;
14
14
15
+ const standaloneInput = document . getElementById ( "standalone" ) ;
16
+ const iterationsInput = document . getElementById ( "iterations" ) ;
17
+
15
18
// This allows aborting and outputting while tests are being run.
16
19
Benchmark . options . async = true ;
17
20
@@ -38,17 +41,22 @@ function addResult(name, result, fn) {
38
41
// @see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
39
42
const 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 - ] + ) * ) ) ? $ / ;
40
43
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 ( ) {
46
45
let url = urlInput . value ;
47
46
if ( url . trim ( ) === "" ) {
48
47
url = "vue.global.js" ;
49
48
} else if ( semverRegex . test ( url ) ) {
50
49
url = `https://cdnjs.cloudflare.com/ajax/libs/vue/${ url } /vue.global.js` ;
51
50
}
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 ( ) ;
52
60
53
61
log ( "Use Vue3: " + url ) ;
54
62
log ( "Benchmarks: " + benchmarks . join ( "," ) ) ;
@@ -112,6 +120,57 @@ async function runTests(benchmarks) {
112
120
}
113
121
}
114
122
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
+
115
174
function injectScript ( src ) {
116
175
return new Promise ( ( resolve , reject ) => {
117
176
const script = document . createElement ( 'script' ) ;
@@ -121,3 +180,5 @@ function injectScript(src) {
121
180
document . head . appendChild ( script ) ;
122
181
} ) ;
123
182
}
183
+
184
+
0 commit comments