* Run model benchmark on BrowserStack. * * Each browser-device pairing is benchmarked in parallel. Results are sent to * the webpage staggered as they are returned to the server. * * The benchmark configuration object contains two objects: * - `browsers`: Each key-value pair represents a brows
(config, runOneBenchmark = getOneBenchmarkResult)
| 174 | * @param runOneBenchmark Function that benchmarks one browser-device pair |
| 175 | */ |
| 176 | async function benchmark(config, runOneBenchmark = getOneBenchmarkResult) { |
| 177 | console.log('Preparing configuration files for the test runner.\n'); |
| 178 | setupBenchmarkEnv(config); |
| 179 | if (require.main === module) { |
| 180 | console.log( |
| 181 | `Starting benchmarks using ${cliArgs.localBuild || 'cdn'} ` + |
| 182 | `dependencies...`); |
| 183 | } |
| 184 | |
| 185 | const promiseQueue = new PromiseQueue(cliArgs?.maxBenchmarks ?? 9); |
| 186 | const results = []; |
| 187 | |
| 188 | // Runs and gets result of each queued benchmark |
| 189 | let tabIndex = 1; |
| 190 | for (const tabId in config.browsers) { |
| 191 | results.push(promiseQueue.add(() => { |
| 192 | return runOneBenchmark(tabId, cliArgs?.maxTries, tabIndex++).then((value) => { |
| 193 | value.deviceInfo = config.browsers[tabId]; |
| 194 | value.modelInfo = config.benchmark; |
| 195 | return value; |
| 196 | }).catch(error => { |
| 197 | console.log( |
| 198 | `${tabId} ${config.benchmark.model} ${config.benchmark.backend}`, |
| 199 | error); |
| 200 | return { |
| 201 | error, deviceInfo: config.browsers[tabId], modelInfo: config.benchmark |
| 202 | } |
| 203 | }); |
| 204 | })); |
| 205 | } |
| 206 | |
| 207 | // Optionally written to an outfile or pushed to a database once all |
| 208 | // benchmarks return results |
| 209 | const fulfilled = await Promise.allSettled(results); |
| 210 | if (cliArgs?.outfile === 'html' || cliArgs?.outfile === 'json') { |
| 211 | for (const benchmarkResult of fulfilled) { |
| 212 | jsonwriter.write(benchmarkResult); |
| 213 | } |
| 214 | } |
| 215 | if (cliArgs?.firestore) { |
| 216 | await pushToFirestore(fulfilled); |
| 217 | } |
| 218 | console.log( |
| 219 | `\n${config.benchmark?.model} model benchmark over ${config.benchmark?.backend} backend complete.\n`); |
| 220 | return fulfilled; |
| 221 | } |
| 222 | |
| 223 | function sleep(timeMs) { |
| 224 | return new Promise(resolve => setTimeout(resolve, timeMs)); |
no test coverage detected
searching dependent graphs…