MCPcopy Index your code
hub / github.com/tensorflow/tfjs / benchmarkModel

Function benchmarkModel

e2e/benchmarks/browserstack-benchmark/benchmark_models.js:61–89  ·  view source on GitHub ↗
(benchmarkParameters)

Source from the content-addressed store, hash-verified

59const KARMA_SERVER = './base';
60
61async function benchmarkModel(benchmarkParameters) {
62 // Load the model.
63 const benchmark = benchmarks[benchmarkParameters.model];
64 const numRuns = benchmarkParameters.numRuns;
65 let model;
66 if (benchmarkParameters.model === 'custom') {
67 if (benchmarkParameters.modelUrl == null) {
68 throw new Error('Please provide model url for the custom model.');
69 }
70 model = await loadModelByUrl(benchmarkParameters.modelUrl);
71 } else {
72 model = await benchmark.load();
73 }
74
75 // Benchmark.
76 let timeInfo;
77 let memoryInfo;
78 if (benchmark.predictFunc != null) {
79 const predict = benchmark.predictFunc();
80 timeInfo = await timeInference(() => predict(model), numRuns);
81 memoryInfo = await profileInference(() => predict(model));
82 } else {
83 const input = generateInput(model);
84 timeInfo = await timeModelInference(model, input, numRuns);
85 memoryInfo = await profileModelInference(model, input);
86 }
87
88 return { timeInfo, memoryInfo };
89}
90
91async function benchmarkCodeSnippet(benchmarkParameters) {
92 let predict = null;

Callers 1

Calls 8

loadModelByUrlFunction · 0.85
timeInferenceFunction · 0.85
profileInferenceFunction · 0.85
generateInputFunction · 0.85
timeModelInferenceFunction · 0.85
profileModelInferenceFunction · 0.85
predictFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…