Skip to content

Commit c4c2aaf

Browse files
authored
executor_runner: print total execution time (#9342)
Makes it more convenient to check perf with the runner.
1 parent f805940 commit c4c2aaf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

examples/portable/executor_runner/executor_runner.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <executorch/runtime/executor/method.h>
3131
#include <executorch/runtime/executor/program.h>
3232
#include <executorch/runtime/platform/log.h>
33+
#include <executorch/runtime/platform/platform.h>
3334
#include <executorch/runtime/platform/runtime.h>
3435
#ifdef ET_EVENT_TRACER_ENABLED
3536
#include <executorch/devtools/etdump/etdump_flatcc.h>
@@ -249,6 +250,7 @@ int main(int argc, char** argv) {
249250
(uint32_t)method.error());
250251
ET_LOG(Info, "Method loaded.");
251252

253+
et_timestamp_t time_spent_executing = 0;
252254
// Run the model.
253255
for (uint32_t i = 0; i < FLAGS_num_executions; i++) {
254256
ET_LOG(Debug, "Preparing inputs.");
@@ -267,17 +269,24 @@ int main(int argc, char** argv) {
267269
(uint32_t)inputs.error());
268270
ET_LOG(Debug, "Inputs prepared.");
269271

272+
const et_timestamp_t before_execute = et_pal_current_ticks();
270273
Error status = method->execute();
274+
const et_timestamp_t after_execute = et_pal_current_ticks();
275+
time_spent_executing += after_execute - before_execute;
271276
ET_CHECK_MSG(
272277
status == Error::Ok,
273278
"Execution of method %s failed with status 0x%" PRIx32,
274279
method_name,
275280
(uint32_t)status);
276281
}
282+
const auto tick_ratio = et_pal_ticks_to_ns_multiplier();
283+
constexpr auto NANOSECONDS_PER_MILLISECOND = 1000000;
277284
ET_LOG(
278285
Info,
279-
"Model executed successfully %" PRIu32 " time(s).",
280-
FLAGS_num_executions);
286+
"Model executed successfully %" PRIu32 " time(s) in %f ms.",
287+
FLAGS_num_executions,
288+
static_cast<double>(time_spent_executing) * tick_ratio.numerator /
289+
tick_ratio.denominator / NANOSECONDS_PER_MILLISECOND);
281290

282291
// Print the outputs.
283292
std::vector<EValue> outputs(method->outputs_size());

0 commit comments

Comments
 (0)