MCPcopy Create free account
hub / github.com/tensorflow/tfjs / benchmark

Function benchmark

e2e/benchmarks/browserstack-benchmark/app.js:176–221  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

174 * @param runOneBenchmark Function that benchmarks one browser-device pair
175 */
176async 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
223function sleep(timeMs) {
224 return new Promise(resolve => setTimeout(resolve, timeMs));

Callers 2

benchmarkAllFunction · 0.85
app_node_test.jsFile · 0.85

Calls 6

addMethod · 0.95
setupBenchmarkEnvFunction · 0.85
pushToFirestoreFunction · 0.85
logMethod · 0.65
writeMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…