(benchmarkParameters)
| 59 | const KARMA_SERVER = './base'; |
| 60 | |
| 61 | async 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 | |
| 91 | async function benchmarkCodeSnippet(benchmarkParameters) { |
| 92 | let predict = null; |
no test coverage detected
searching dependent graphs…