Skip to content

executor_runner: print total execution time #9342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions examples/portable/executor_runner/executor_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <executorch/runtime/executor/method.h>
#include <executorch/runtime/executor/program.h>
#include <executorch/runtime/platform/log.h>
#include <executorch/runtime/platform/platform.h>
#include <executorch/runtime/platform/runtime.h>
#ifdef ET_EVENT_TRACER_ENABLED
#include <executorch/devtools/etdump/etdump_flatcc.h>
Expand Down Expand Up @@ -249,6 +250,7 @@ int main(int argc, char** argv) {
(uint32_t)method.error());
ET_LOG(Info, "Method loaded.");

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

const et_timestamp_t before_execute = et_pal_current_ticks();
Error status = method->execute();
const et_timestamp_t after_execute = et_pal_current_ticks();
time_spent_executing += after_execute - before_execute;
ET_CHECK_MSG(
status == Error::Ok,
"Execution of method %s failed with status 0x%" PRIx32,
method_name,
(uint32_t)status);
}
const auto tick_ratio = et_pal_ticks_to_ns_multiplier();
constexpr auto NANOSECONDS_PER_MILLISECOND = 1000000;
ET_LOG(
Info,
"Model executed successfully %" PRIu32 " time(s).",
FLAGS_num_executions);
"Model executed successfully %" PRIu32 " time(s) in %f ms.",
FLAGS_num_executions,
static_cast<double>(time_spent_executing) * tick_ratio.numerator /
tick_ratio.denominator / NANOSECONDS_PER_MILLISECOND);

// Print the outputs.
std::vector<EValue> outputs(method->outputs_size());
Expand Down
Loading