* Benchmark stable execution of the run function. * * @param run The run function. * @param dev The device to sync during each run. * @param number The number of times to compute the average. * @param repeat The number of times to repeat the run.
(run: () => void, dev: DLDevice, number = 10, repeat = 1)
| 930 | * @param repeat The number of times to repeat the run. |
| 931 | */ |
| 932 | async benchmark(run: () => void, dev: DLDevice, number = 10, repeat = 1): Promise<number[]> { |
| 933 | // Skip first run as it can involve GPU warmup and module loading time. |
| 934 | const perf = compact.getPerformance(); |
| 935 | const results = []; |
| 936 | |
| 937 | // run with new scope |
| 938 | this.withNewScope(run); |
| 939 | await dev.sync(); |
| 940 | |
| 941 | for (let k = 0; k < repeat; ++k) { |
| 942 | const tstart = perf.now(); |
| 943 | for (let i = 0; i < number; ++i) { |
| 944 | this.withNewScope(run); |
| 945 | } |
| 946 | await dev.sync(); |
| 947 | const tend = perf.now(); |
| 948 | results.push((tend - tstart) / number); |
| 949 | } |
| 950 | return results; |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * Check whether we enabled asyncify mode |
nothing calls this directly
no test coverage detected